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.
how to get/use the name of a part to name another Mate Connector in FS? (edited, used to say "part")
joshtargo
Member Posts: 289 EDU
I get an error when I use getProperty and then setProperty, but the query field can see the name. how can I capture and use it during an FS execution?
0
Answers
you have to get the name in editing logic, store it somewhere in the definition, and retrieve it in the main function.
GetProperty only works in certain contexts which are listed in the documentation.
Custom FeatureScript and Onshape Integrated Applications
@Caden_Armstrong what function do I use in editlogic to grab the name?
getproperty will get the name of a part.
Custom FeatureScript and Onshape Integrated Applications
this is returning "undefined" within edit logic. am i doing it wrong?
var mc = definition.mc.subqueries[i];
have you tested that MC is a valid query for a part body?
Custom FeatureScript and Onshape Integrated Applications
Hey @joshtargo I may be off base here, but there are some 'quirks' to Plane and Mate Connector names in Featurescript - at least when it comes to setting names for Planes and Mate Connectors with featurescript (… you can't). I just threw together a quick test to see if I ran into the same error you do, and I'm getting the name coming back as undefined. I'm guessing that the same issues that prevent FS setting a name on a Plane or Mate Connector also prevent you from accessing the names. (…. or my hastily written code has the same issues as yours)
@Caden_Armstrong the query is valid, but is a mate connector, and I guess you can't rename MCs in FS?
@joshtargo You need to create a string variable in your custom feature "precondition" section with the UIHint always_Hidden. Then use the editing logic function to edit that variable which you don't see in the interface, but can reference in your main body.
Please note: setProperty will not override any property you've manually edited in the part studio. This got me off guard before.
Also skip the
var mc = definition.mc.subqueries[i];
line and write:
Directly. Editing logic functions are a weird like that
I didnt realize you were trying to set the name of a mate connector. Thats a different question to your title.
As Jed said, you can't. Get and Set property are featurescript shortcuts to part metadata. Planes and mateconnectors don't have metadata, so their names in the UI are derived from their features. Some of this functionality seems to be hardcoded to things like the name of the feature type (cPlane named features are the only way to name a plane for example).
Custom FeatureScript and Onshape Integrated Applications
@christopher_dziuba I have the subquery as it's own variable because I used that variable multiple times in the main loop before i copied the code to try the edit logic trick.
@joshtargo copying code into editing logic should work but I think this is a legitimate bug they lack variable assignment to external references sometimes. Also @Caden_Armstrong is correct:
However you can make an extremely simple mate connector Featurescript to make custom mate connectors, even just copy and paste the original mate connector source AND add an attribute to the mate connector since it can be added to any entity:
Then later you can reference this attribute and modify as needed. Much easier then using editing logic functions and properties.
Also @joshtargo are you a pilot? Profile pic give ideas :)
I was, but not current anymore. the pic is from when I was taking photographs from a helicopter
@joshtargo That's pretty cool, you'd be handy in a zombie apocalypse :P Anyway let us know if any of that worked
@christopher_dziuba it will likely not be able to work because mate connectors don't have names, they are named after the feature that created them.
@joshtargo it has to work because an attribute is not a property. It's just an arbitrary variable that you assign to an entity.
It then just lives with that entity until some other featurescript picks it up! like this:
that would work, but I don't want to make a second, specialized mate connector FS just for this naming thing. I'm ok without it.