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.
Is it possible to configure properties of a body with Featurescript?
Kyle_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!
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:
0
Best Answers
-
MichaelPascoe Member Posts: 1,989 PRO
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! Learn How to FeatureScript Here 🔴0 -
EvanReese Member, Mentor Posts: 2,144 ✭✭✭✭✭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 Reese0
Answers
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! Learn How to FeatureScript Here 🔴
@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.
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.