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.
Automatically referencing geometries as input for new feature through API
leon_poot
Member, Developers Posts: 87 ✭✭✭
Apologies in advance for the abstract problem description. I hope I'll be able to explain it somewhat properly. If not, let me know what information you're missing. My problem is as follows:
Let's say I have two Feature Studios. One which creates a straight line, and one which creates an arc.
So that's the setting.
Now the real question: Can I reference vertices and/or edges through the API?
https://forum.onshape.com/discussion/4855/grouping-enum
I have tried to get some inspiration from this discussion, where geometries are referenced by importing another Part Studio and somehow taking all necessary info from the contexts. Something called "Lookup Table" is mentioned, but I haven't been able to figure out how this works.
Let's say I have two Feature Studios. One which creates a straight line, and one which creates an arc.
- I need to be able to instantiate these in any given order, and with any number of straight lines or arcs, so for example straight - straight - arc -straight - arc - arc, all in the same Part Studio.
- Any new added feature must start at the end of a previous one, and be tangent to it too. (I.e. I will need a point and a direction vector as reference).
So that's the setting.
Now the real question: Can I reference vertices and/or edges through the API?
https://forum.onshape.com/discussion/4855/grouping-enum
I have tried to get some inspiration from this discussion, where geometries are referenced by importing another Part Studio and somehow taking all necessary info from the contexts. Something called "Lookup Table" is mentioned, but I haven't been able to figure out how this works.
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
Tagged:
0
Best Answers
-
mark_noyes Member, Onshape Employees, Developers Posts: 21The geometryIds are always literal Id values rather than general queries. Each vertex, face, edge, body, etc. has a geometry Id that can be used to reference that entity. These id values are not user-assignable, but are effectively an index into the model regeneration structure. If you need to reference a vertex, edge or some other piece of the model that was created by an earlier feature addition you can get the id values by evaluating a FeatureScript expression using the Evaluate FeatureScript API call.
Take a look at the "FeatureScript Evaluation" and "Example 3" sections of the Feature list API topic in the dev-portal help area. The "script" field of the input should hopefully be fairly obvious from the examples. To get geometryId values out of a function evaluation, use the transientQueriesToStrings function, as demonstrated in Example 3. If you need to pass geometryId values back in, you do that using the "queries" field of the evaluation input as shown in the FeatureScript Evaluation section.
In your second post you asked "How do I know which geometryId to put into the message". I expect you will want to use the qCreatedBy query along with a featureId from a feature added in a prior step to do the evaluation and rely on additional knowledge embedded in your software. Decisions such as "which end of the line should I choose" are details that you will need to work out.5 -
leon_poot Member, Developers Posts: 87 ✭✭✭Thank you very much, @mark_noyes. I'll have a look at the "FeatureScript Evaluation" and "Example 3" sections like you said and report back when I've figured it out!"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless5
Answers
Here the "geometryIds" seems to be the key, which I'd have to put into the message when using the UpdateFeature API (just as one would for a "normal" length parameter for example). How do I know which geometryId to put into the message, or even better: how do I name a geometry in the referenced feature so that I can reference it using that name?
https://cad.onshape.com/documents/8c428a2d9b209747a8e2b960/w/7f8af340483a59e6f839aa7d/e/b1af2aee4c64b16ca8f1ecd4
with SOMEKINDOFQUERY being a Feature Script query?
Take a look at the "FeatureScript Evaluation" and "Example 3" sections of the Feature list API topic in the dev-portal help area. The "script" field of the input should hopefully be fairly obvious from the examples. To get geometryId values out of a function evaluation, use the transientQueriesToStrings function, as demonstrated in Example 3. If you need to pass geometryId values back in, you do that using the "queries" field of the evaluation input as shown in the FeatureScript Evaluation section.
In your second post you asked "How do I know which geometryId to put into the message". I expect you will want to use the qCreatedBy query along with a featureId from a feature added in a prior step to do the evaluation and rely on additional knowledge embedded in your software. Decisions such as "which end of the line should I choose" are details that you will need to work out.