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 have feature definitions toggle depending on whether a query is emtpy?
dave_cowden
Member, Developers Posts: 475 ✭✭✭
I want to do something like this:
IE, i want to provide some other inputs, but only if the user has entered a query that selects things.
I tried
but it appears that even when the user selects nothing, we get an empty query, not undefined ( unfortunate )
i know i can do this too:
but it kind of stinks beause the user has more clicks:
definition.selectedBodies is Query;
if ( isQueryEmpty(definition.selectedBodies ) ){
definition.someOtherProperty is boolean;
}
IE, i want to provide some other inputs, but only if the user has entered a query that selects things.
I tried
if ( definition.selectedBodies != undefined ){
....
but it appears that even when the user selects nothing, we get an empty query, not undefined ( unfortunate )
i know i can do this too:
but it kind of stinks beause the user has more clicks:
definition.doYouWantToDoWhatever is boolean;
if ( definition.doYouWantToDoWhatever ){
definition.selectedBodies is Query;
definition.someOtherProperty is boolean;
}
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,211Yes and no.
No, it's not possible to predicate inputs on query resolution (the way you can on enums or booleans) because changes unrelated to the feature can make a query resolve differently. For instance, a feature deleted earlier in the history can make a query that was previously empty resolve to something non-empty, which would cause a precondition error in the feature.
Yes, you can work around this (and save user clicks) with an editingLogicFunction. You could even make the doYouWantToDoWhatever boolean hidden with a UIHint but then the user could end up stuck in the wrong state with no obvious recourse. Let me know if you need more info on how to do this.
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
No, it's not possible to predicate inputs on query resolution (the way you can on enums or booleans) because changes unrelated to the feature can make a query resolve differently. For instance, a feature deleted earlier in the history can make a query that was previously empty resolve to something non-empty, which would cause a precondition error in the feature.
Yes, you can work around this (and save user clicks) with an editingLogicFunction. You could even make the doYouWantToDoWhatever boolean hidden with a UIHint but then the user could end up stuck in the wrong state with no obvious recourse. Let me know if you need more info on how to do this.