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.
Alternative to lots of hidden feature params?
EvanReese
Member, Mentor Posts: 2,135 ✭✭✭✭✭
I'm doing a lot of UI logic that changes based on user selections. I'm doing it by using hidden boolean parameters and toggling them with editing logic. For example, the UI might look different depending on whether someone picks a vertex, edge, non-planar face, planar face, or nothing. My issue, is that there are getting to be quite a few of booleans. I also have some hidden integers for point indexes. I'd really love to be able to just have one hidden parameter that's a map of all of my booleans, then address it in the UI. I'd fill it with something like
{"pointIndex" : 1, "noSelection" : false, "isVertex" : false, "isEdge" : true, "isFace" : false, "isPlanarFace" : false}
Is there a way to do something like that? I can get by without it, but it just gets clickity-clackity to write, and fluffs up the code making it harder to read.
{"pointIndex" : 1, "noSelection" : false, "isVertex" : false, "isEdge" : true, "isFace" : false, "isPlanarFace" : false}
Is there a way to do something like that? I can get by without it, but it just gets clickity-clackity to write, and fluffs up the code making it harder to read.
Evan Reese
0
Best Answers
-
NeilCooke Moderator, Onshape Employees Posts: 5,683You have to remember that the UI is a predicate so it cannot react to any logic created in the body of the script (apart from Editing Logic).Senior Director, Technical Services, EMEAI0
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Evan_Reese said:if (definition.UI.boolean1)
{
*Other parameters to show*
}0
Answers
Functionally, I don't think it would really differ too much from having a hidden parameter map as you are suggesting,
as in both cases you still need to have an if statement checking a map variable.
If your biggest gripe is a messy precondition, moving it away into a precondition would at least organize things.
then in my precondition something like
if (definition.UI.boolean1)
{
*Other parameters to show*
}
I struggle with code formatting on the forums but here's an example script
https://cad.onshape.com/documents/74b868c81ffd51b8b4a9c6a5/w/facc72e9362395db8a26dc6b/e/3cbb4cc8c851cbb31b6aa7b0