Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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
adamohern
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.
(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.
0
Comments
This looks great. I'll give it a try.
Anyway, thanks!
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).