What query will give me the solid body that owns a face?

dave_cowden
dave_cowden Member, Developers Posts: 484 ✭✭✭
I have a face, and I thought this would give me the body that owns it:

var theBody = qOwnerBody(definition.face );

But that just gives me the face again.  I also tried 

var theBody = qOwnerBody(qOwnerBody(definition.face));

but that gives the same thing too.  The body is a user-created body so i do not have programmatic access to the id to use qCreatedBy.

This code works, but its really insane just to find the owning body:
<div>&nbsp; &nbsp; var tangentPlane = evSurfaceDefinition(context, {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "face" : definition.face</div><div>&nbsp; &nbsp; });</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; var originalObject =qContainsPoint(qBodyType(qEverything(EntityType.BODY),BodyType.SOLID),tangentPlane.origin );</div>


Shouldn't you be able to find the solid body that owns a face using qOwnerBody?  I think this code will generally work but its pretty nasty and there are some corners in which we could find multiple bodies if we happened to have a face on a boundary between two solids.

Answers

  • dave_cowden
    dave_cowden Member, Developers Posts: 484 ✭✭✭
    oh sorry, in that last code i pasted an older version, sorry.

    the last part should be 

    <div>&nbsp; &nbsp; var tangentPlane = evFaceTangentPlane(context, {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "face" : definition.surface,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "parameter" : vector(0.5, 0.5)</div><div>&nbsp; &nbsp; });
    
    of course the above returns a surface, not a tangent plane.</div>
  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,274 image
    qOwnerBody should work -- assuming the face is on that body and not, say, part of a different body (perhaps a surface body).  I'm surprised it gives you a face.  Does the output of debug(context, qOwnerBody(definition.face)) confirm that it resolves to one face?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • dave_cowden
    dave_cowden Member, Developers Posts: 484 ✭✭✭
    Yes, it does. I also sebugged it graphically to see what it selected too.

    This is a pretty large project, so like that other extrude weirdness I'll try to narrow it down to an easier repro before having you look into it