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.

Is it possible to configure properties of a body with Featurescript?

Kyle_BurtKyle_Burt Member Posts: 11 PRO
I'm trying to find out if it's possible to configure a body using Featurescript.

The concept:
-Prompt for two user-selected bodies
-Get string from property "Name" of each part
-Create a new simple body (in this case a cylinder)
-Configure the cylinder to have two configurations
-Set configured "Name" properties of the cylinder to those of the user-selected parts

This seems relatively straightforward, but I can't find any documentation on it, so am assuming it's not possible.
Any guidance or confirmation of my assumption would be greatly appreciated.


Thanks!
Tagged:

Best Answers

  • MichaelPascoeMichaelPascoe Member Posts: 1,964 PRO
    edited August 2023 Answer ✓

    Setting the property is not too difficult, use setProperty. Getting the property is a little tricky as it takes place after the feature has been created. So what you can do is run part of the feature within edit logic, store the data in the parameters, then access the those parameters in the main feature. Here is a summarized example of this: getProperty - forum post


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • EvanReeseEvanReese Member, Mentor Posts: 2,085 ✭✭✭✭✭
    Answer ✓
    Just to add some understanding of the challenge here, think of the entire part studio as some code that runs (which it is), and it runs in a certain order. The code that sets the name of the part happens after all of the features are done. However Onshape's Custom Tables run after that. That's why features cannot read part properties (and cannot override user-set ones), but Custom Tables can read them with getProperty(). That's my layperson understanding anyway.

    @MichaelPascoe I didn't realize that getProperty() works in editing logic, which is awesome! I like your solution.

    @Kyle_Burt I think your idea of making two features might be the most robust since editing logic won't update unless you're actively editing the feature. One feature can name the part, and the subsequent one can read it. If getProperty() doesn't work in the feature body even in that case (I've not tested it), you could use setAttribute() to store the name data which can be read by the downstream feature.

    Evan Reese

Answers

  • Kyle_BurtKyle_Burt Member Posts: 11 PRO
    If it's not possible to configure, I'd settle for being able to push the parent "Name" to the new body. I've been having trouble figuring out how to use getProperty and setProperty without having to create two Featurescripts.
  • MichaelPascoeMichaelPascoe Member Posts: 1,964 PRO
    edited August 2023 Answer ✓

    Setting the property is not too difficult, use setProperty. Getting the property is a little tricky as it takes place after the feature has been created. So what you can do is run part of the feature within edit logic, store the data in the parameters, then access the those parameters in the main feature. Here is a summarized example of this: getProperty - forum post


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • EvanReeseEvanReese Member, Mentor Posts: 2,085 ✭✭✭✭✭
    Answer ✓
    Just to add some understanding of the challenge here, think of the entire part studio as some code that runs (which it is), and it runs in a certain order. The code that sets the name of the part happens after all of the features are done. However Onshape's Custom Tables run after that. That's why features cannot read part properties (and cannot override user-set ones), but Custom Tables can read them with getProperty(). That's my layperson understanding anyway.

    @MichaelPascoe I didn't realize that getProperty() works in editing logic, which is awesome! I like your solution.

    @Kyle_Burt I think your idea of making two features might be the most robust since editing logic won't update unless you're actively editing the feature. One feature can name the part, and the subsequent one can read it. If getProperty() doesn't work in the feature body even in that case (I've not tested it), you could use setAttribute() to store the name data which can be read by the downstream feature.

    Evan Reese
  • Kyle_BurtKyle_Burt Member Posts: 11 PRO
    Thanks for the input @MichaelPascoe and @Evan_Reese!
    I too did not know that getProperty() could work there.

    I'll likely lean into the idea of two features just to try and make it stronger.  I'll play around with setAttribute() a bit more as well to see if that'll help with brevity.
Sign In or Register to comment.