Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

boilerplate code to disambiguate query results

adamohernadamohern Member, OS Professional Posts: 216 PRO
Assume I'm creating a plane tool like the SolidWorks plane tool. By selecting a few different references, the tool will auto-magically figure out what plane type is needed based on the types of geometry selected: one face creates an offset plane; two faces creates a midplane, one edge creates a normal plane, one edge and one point creates a normal-thru-point plane, etc.

(The above is just an example, I have many other uses for this kind of behavior.)

I'm told there is not currently a native function that returns the object type resulting from a given query. In other words, given a queried result, I have no way of knowing if it's a plane, face, edge, vertex, etc. The only way I know of to deal with this problem is to do a series of try() statements, each attempting to use the geometry in a specific way. Failure moves on to the next try() statement, and keeps trying different things until one of them succeeds.

But what if I just want to *know* what the query result is, not operate on it? Could someone help me write a boilerplate function that would help to disambiguate the result of a query? It's okay if it's just a bunch of try() statements. I don't care how it works, as long as I have a simple, re-usable chunk of code that tells me what the user has selected.

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    Adam, have you seen the cPlaneLogic function at the bottom of cplane.fs in std?  It's one way of doing exactly that.  Another way is using evCurveDefinition and evSurfaceDefinition to look at individual edge and face queries.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    Oh, right on! That's perfect. I assumed it wasn't there because--for me, at least--the plane tool in Onshape doesn't have any automatic behavior. I have to manually select the plane type from the drop-down.

    This looks great. I'll give it a try.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    The plane tool uses that function to select the plane type automatically based on what you have selected when you first click the plane button.  It doesn't have any automatic behavior afterwards.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    The plane tool uses that function to select the plane type automatically based on what you have selected when you first click the plane button.  It doesn't have any automatic behavior afterwards.
    Ah, I see. That's unfortunate. I would prefer if it were like SolidWorks, where it refines your plane type based on selection during feature creation. I find that much more intuitive than relying solely on pre-select.

    Anyway, thanks!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    With FS you can make that customization yourself I believe :)  Just either get rid of the old definition check in cPlaneLogic or make it check that the plane type itself was not explicitly set.

    You can also add a boolean argument to the cPlaneLogic function as the last argument (this is currently undocumented but it makes the logic function run when the feature is edited, not just created).

    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    With FS you can make that customization yourself I believe :)
    Sing choirs of angels.
Sign In or Register to comment.