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: 3,019 PRO
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.
0
Best Answers
-
You 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, EMEA0
-
Yes, in order to get conditional visibility you need the booleans listed out explicitly. Our UI only has logic for dealing with those explicitly listed parameters. It sounds like you've made the simplest functional solution.Evan_Reese said:if (definition.UI.boolean1)
{
*Other parameters to show*
}0
Answers
-
I just realized I can probably use a hidden enum instead of a bunch of booleans for isVertex, isEdge etc. It would still be nice to have a single place to put all of the info that the UI references though.0
-
Closest solution you'd have would be to put all of the hidden parameters into a single predicate which gets called in your precondition.
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.2 -
That's a good idea, Caden. Thanks!0
-
You can also have a single "isAnything" field which contains a map/array/whatever data structure you want. That way you don't need to keep modifying the precondition to add new non-user-visible fields.1
-
Thanks, Kevin. I'd hoped that would work, but I'm not sure it's what I'm looking for. I'm wanting to hide and show UI parameters based on the contents, but it seems like I'm not able to access anything in the map. What I'd love to do is something like this:kevin_o_toole_1 said:You can also have a single "isAnything" field which contains a map/array/whatever data structure you want. That way you don't need to keep modifying the precondition to add new non-user-visible fields.annotation { "Name" : "UI settings"}isAnything(definition.UI);
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/3cbb4cc8c851cbb31b6aa7b00 -
You 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, EMEA0
-
Yeah, I get that. I'd just hoped there would be a way to store a lot of booleans or enums inside of one isAnything param and access them, but I think I can't get inside of an array or map within the predicate. It seems like only booleans, enums, and lookup tables can drive visibility of other parameters. Is that right?NeilCooke said:You 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).0 -
Yes, in order to get conditional visibility you need the booleans listed out explicitly. Our UI only has logic for dealing with those explicitly listed parameters. It sounds like you've made the simplest functional solution.Evan_Reese said:if (definition.UI.boolean1)
{
*Other parameters to show*
}0 -
Thanks folks. For future readership, if you have a number of independent things to control in the UI via editing logic, use booleans. If you have a lot of mutually exclusive options, you can use an enum. You can't access anything in a container (i.e. map, array etc) within the precondition, so creating a map of booleans won't work.0



