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.

Query Part from Part Studio to Use as Input for Custom Feature

Kyler_WalkerKyler_Walker Member Posts: 49 PRO
I have written a custom feature that takes a part as an input and performs operations using that part.  I am writing new a feature that uses the first feature. When using the new, top level feature, the part that is used as an input for the referenced feature should be predetermined, not chosen by the user.  I can have this part exist in the same document as my top level feature.  The user has no reason for this part to exist in their part studio.  Is there a way I can query the part so I can use it as an input to the referenced feature without bringing the part into the user's part studio?   

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 534
    Sounds like you want the second feature to have no input, but know about the geometry chosen in the first feature. That certainly involves storing something in the context. What the minimum something is depends on what you want to use it for, but in the most general case, you need to instantiate the parts.

    Without instantiating, you cannot query in a context for geometry that does not exist in that context. It's possible there may be a workflow to only, say, evaluate some data in the other Part Studio's context, store that data, and use that data instead of a query in your downstream workflow. But if you need geometry in an operation (like say, a boolean) that geometry needs to be present in the Part Studio. You will need to instantiate the bodies from the other Part Studio into the current one (and possibly delete them at the end).

    Performance-wise, it should not be as expensive to copy that geometry into the current context as it was to build it originally (since that data is cached in versions).

    To mark which bodies are needed between the features, one option is something like
    setAttribute(context, { "entities" : qCreatedBy(id + "instantiator", EntityType.BODY, "name" : "bodiesForFeatureX", "value" : true })
    in the first feature, and something like
    qHasAttribute("bodiesForFeatureX")
    in the second feature.
  • Kyler_WalkerKyler_Walker Member Posts: 49 PRO

    To mark which bodies are needed between the features, one option is something like
    setAttribute(context, { "entities" : qCreatedBy(id + "instantiator", EntityType.BODY, "name" : "bodiesForFeatureX", "value" : true })
    in the first feature, and something like
    qHasAttribute("bodiesForFeatureX")
    in the second feature.
    Thanks for the explanation.  I do need to use the part to create geometry, so I guess I will instantiate it and then delete it at the end.  The setAttribute() function is new to me, but it looks like it will be very convenient.
Sign In or Register to comment.