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.

Options

How to get feature dependencies via script?

In the UI, you can see what preceding features a certain feature depends on.
How do you get that information via the REST API or a featurescript evaluation call?



Thanks in advance :smile:

Best Answer

  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    Answer ✓
    Short answer: no.

    Long answer:
    You could
    • Get the IDs of all selected geometry from the parameters of your selected feature
    • Traverse the feature list, getting the feature id for each feature
    • running an "EvaluateFeatureScript" query in the API, looking at qCreatedBy(featureId)
      Evaluate the results of that qcreatedby, and look at all of the geometry IDs, if any match your step 1 Ids, you have a dependency
    • If you only want 1st level dependencies, stop there
      If you want the whole list of dependencies (dependencies of dependencies), you then repeat the process for any dependent features until you run down the list
    Not an easy process, but possible...

Answers

  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    Answer ✓
    Short answer: no.

    Long answer:
    You could
    • Get the IDs of all selected geometry from the parameters of your selected feature
    • Traverse the feature list, getting the feature id for each feature
    • running an "EvaluateFeatureScript" query in the API, looking at qCreatedBy(featureId)
      Evaluate the results of that qcreatedby, and look at all of the geometry IDs, if any match your step 1 Ids, you have a dependency
    • If you only want 1st level dependencies, stop there
      If you want the whole list of dependencies (dependencies of dependencies), you then repeat the process for any dependent features until you run down the list
    Not an easy process, but possible...
  • Options
    felix_hahnleinfelix_hahnlein Member Posts: 4 EDU
    Thanks a lot.
    Some subtleties for everyone who wants to do something similar:
    • EvaluateFeatureScript will evaluate the featurescript with the rollbackbar-index indicated by the REST API call. The rollbackbar is at the end of the document by default. That means that geometric entities which have been used and effectively deleted by intermediate features, won't be returned. I think that in the official python onshape-client package, the rollbackbar parameter has not been exposed for the eval_featurescript function. I had to modify that part of the code to pass it through.
    • qCreatedBy will return the Id of newly created, but not of modified geometry. However, modified Brep entities will get a new geometryId which can be referenced by features. So in order to trace which geometryIds have been "created" by which operation, you have to call qCreatedBy at every step of the feature list also for all preceding features. It's a double loop, so we call qCreatedBy O(n^2) times, where n is the total number of features.
    At least that's how I got it to work in the end. I'm open to suggestions
  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    You could also just suppress each feature in the tree and see what breaks as a result.
    A less elegant solution, but might be effective.
Sign In or Register to comment.