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.
Featurescript - Allow Duplicate Precondition Conditional Parameters
owen_sparks
Member, Developers Posts: 2,660 PRO
Hi folks.
I'd like to be able to declare the same conditional parameter multiple times in a FS precondition.
Example use case:-
Here I have a feature to make a hole for a connector. On some parts I want to offer the option to surface mount it, or make it flush with the target part. So I'd like to just have one "definition.IsFlush" option, one definition.addvoid" and one definition.targetpart". Instead we need to use a unique names for each set of declarations which is messy and prone to errors later in the code. (It's not appropriate to offer these options for other selections so I can't just put them in the unconditional part.)
<code> if (definition.OperationType == DesiredPart.Connector_Bolt)<br> { <br> annotation { "Name" : "Flush" } //Transforms Part such that top face is flush with targtet.<br> definition.IsFlush is boolean;<br><br> if (definition.AddConnectorBoltVoid)<br> {<br> annotation { "Name" : "Target Part", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }<br> definition.TargetPart is Query; <br> }<br> }
//Optional Parameters based on choice form horizontal enum <br>
and later
<code> if (definition.OperationType == DesiredPart.Connector_Nut)<br> { <br> annotation { "Name" : "Flush" } //Transforms Part such that top face is flush with targtet.<br> definition.IsFlush_Nut is boolean;<br><br> if (definition.AddConnectorNutVoid)<br> {<br> annotation { "Name" : "Target Part", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }<br> definition.TargetPart_Nut is Query; <br> }<br> }
//Optional Parameters based on choice form horizontal enum <br>
Cheers,
Owen S.
Business Systems and Configuration Controller
HWM-Water Ltd
HWM-Water Ltd
Tagged:
3
Comments
You could use
if(definition.operationType == DesiredPart.CONNECTOR_NUT || definition.operationType == DesiredPart.CONNECTOR_BOLT)
if you wanted the parameters to show for bothCONNECTOR_NUT
andCONNECTOR_BOLT
. (||
is 'or')IR for AS/NZS 1100
HWM-Water Ltd
Another workaround is to use different ids at the two places (as you've done), and in your feature, add code like
definition.TargetPart = definition.TargetPart_Nut
There is a fair amount of Onshape's internal code which relies on those parameter ids being unique, and it would be especially difficult to handle the case of two parameters with the same id but different specifications. For that reason I would not expect this particular suggestion to be implemented as suggested any time soon.
The other thing you could do if you end up needing to keep them separate for simplicity is using editing logic to always update the hidden ones to match the one that is currently showing. I can go into a more detailed explanation if you are curious about how to do this.
HWM-Water Ltd
To save you a bit of time, the part of the FM that specifies what I am talking about is the "Editing logic function" section of this page. Happy reading!
HWM-Water Ltd
HWM-Water Ltd