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.

How do I add a custom Feature I wrote in FeatureScript to my PartStudio using the API?

lebenitolebenito Member Posts: 15
I found this question a couple times in a similar way but there never was a clear answer to that Problem.
I also read through every documentation and Examples there are but there just isn't anything that works. I've tried so many things that I cannot even list them.
Even when I try the examples directly from the Developer Portal they wont work.

Can anyone please give me a clear answer I've been searching for hours.
I am using the onshape_client in python by the way.







Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Am I understanding right that you have a versioned Feature Studio with a custom feature, and you want to add an instance of that custom feature to a Part Studio with the API?

    If so, you can add a custom feature to a Part Studio with the API the same way you add a standard feature. See documentation here.

    Your python code will need to POST to /api/partstudios/DWE/features with the JSON for a "feature". To determine that JSON needed, you should add the custom feature to any Part Studio manually, then get the JSON for all features in that feature list with /api/partstudios/DWMVE/features. You can adjust that JSON however you like in your code, to change e.g. the feature parameters.

    The only thing that makes the custom feature different from a standard feature is that it will have a "namespace" in its JSON, which contains the document id, version id, and element id of the Feature Studio you wrote the feature in.
  • caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    You probably already know parts of this response, but I'll leave it here for future readers.

    You'll need to use the Add Feature end point in order to add your feature to the tree.
    Setting up your input object can be tricky, and I assume is where you are having trouble.
    My recommendation is to add your feature to the feature tree (manually in a test studio), and then grab the 'feature definition' via the Get Features endpoint. 
    The object format that the feature inside of the Get Features return is usually the same as the input for Add Feature.
    This way you can just copy what you see in the Get function and use it in your Post.

    Something to pay attention to (that won't be obvious in the Get Features object) is the 'namespace' parameter.
    If you are adding the feature to a studio in the same document as the featurestudio, the namespace will be a local reference.
    If you want to add your feature to a different document, you'll need the full namespace referencing the document and version.
    Easy way to get this is to do the above step with a different document than what you developed in.

    If you've done all that and still facing errors, it could be related to your specific feature/parameters, (But you should be getting error messages from the API back)
    I know that there are currently some limitations in constructing queries in certain types of inputs.
    For example, I don't think you can use a part studio parameter and select a specific body from the selected part studio, since all queries in an API call are only called against the target studio.
  • lebenitolebenito Member Posts: 15
    Alright thanks that already helps alot.
    But this would not work if I am also using the API to write the FeatureScript.
    So there is no way to do this with the API?:
    1. Add an FeatureStudio in a document ( works )
    2. Write in the created FeatureStudio ( works )
    3. Add a new PartStudio to the same document ( works )
    4. Add this just created Feature to the PartStudio ( does not work )
    That was my original plan, but it seems like I just need to find a workaround and change the plan for the project a little bit.
    Thanks alot though, your answers still helped me.
Sign In or Register to comment.