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: Editing Logic Function does not update length parameter in Feature UI

Have looked through the documentation as well as the Spur Gear example code, but I seem to be missing something obvious. I would like for the Logic Editing Function of my Custom Feature to change a numerical value entered by the user, and for this updated value to be reflected in the Feature UI dialog. When the user changes any parameter in the Feature UI, the Logic Editing Function is triggered. I modify the corresponding value in the 'definition' variable and return it from the function. This appears to work for boolean values, but does not work for my numerical value.
I've attached a minimal document illustrating my issue here:
https://cad.onshape.com/documents/99f64ae634cf6ee14ab3fece/w/7f6c6a530464ce65695a2d3b/e/ec2fc7c827f04f821c42d795
(As an aside, when I try to 'Ask a Question' directly in the Featurescript subforum, it indicates I am not allowed to post questions there. Does that forum require additional privileges? Or am I just asking really silly questions...)
I've attached a minimal document illustrating my issue here:
https://cad.onshape.com/documents/99f64ae634cf6ee14ab3fece/w/7f6c6a530464ce65695a2d3b/e/ec2fc7c827f04f821c42d795
(As an aside, when I try to 'Ask a Question' directly in the Featurescript subforum, it indicates I am not allowed to post questions there. Does that forum require additional privileges? Or am I just asking really silly questions...)
0
Best Answer
-
Alex_Kempen Member Posts: 250 EDU
Sure. The bug appears to occur only when a field value is overwritten by editing logic immediately after it is submitted. For example, if the user enters a value into definition.length, the bug occurs if the editing logic immediately attempts to set definition.length to something else. So so long as the trigger for updating definition.length is not the user changing definition.length (like if it triggers in response to definition.myBoolean or definition.otherLength or whatever), everything works as expected. Thus, since overwriting a parameter immediately after a user changes it is pretty dubious from both a UX and a general usefulness perspective, I don't think the bug you've found is very likely to actually rear its head under "real-world" conditions.
Software Developer at Epic Systems
FRC Design Mentor - Team 1306 BadgerBots0
Answers
FRC Design Mentor - Team 1306 BadgerBots
This behavior isn't critical - just nice to have a responsive UI.
FRC Design Mentor - Team 1306 BadgerBots
As you stated, changing other numerical values does produce the expected behavior in the 'length' parameter. The exception appears to be if one opens the UI dialog and *first* changes the length parameter before making any other changes - in which case, the 'length' parameter remains unresponsive despite changes to other inputs until the UI dialog is closed and reopened. At least, that is the behavior I am observing in my minimal example linked above. Oh well. I guess I will just have to work around it for now.
In any case, I really do appreciate your time and effort, so thank you!
To extend this to a thought experiment in the standard library, imagine if the requirements for the name parameter of the variable feature (cannot start with a number, no spaces or other special characters) enforced themselves automatically by deleting any invalid characters as they were entered. Clearly, this would be a disaster for the user experience, as lots and lots of people would likely be confused when they attempt to enter a variable name like My variable and it immediately snaps to Myvariable. Instead, the current behavior of explicitly highlighting the name field and displaying an appropriate error message (Variable names start with a letter and can only contain letters, numbers, and _) makes it clear to the user that the input is incorrect and gives them a chance to fix it in a way that makes the most sense to them.
FRC Design Mentor - Team 1306 BadgerBots
I've been fiddling with this and I think there are possibly a few things going wrong here, and I think it's because the Spur Gear feature is trying to be a bit too smart, and maybe also the https://cad.onshape.com/FsDoc/uispec.html#editing-logic-function-arguments editing logic function is not always getting triggered when some things change. Others have encountered problems too like;
Things I've noticed are;
1. If I create a variable or configuration variable and use it as the value in in the Spur Gear feature's feature UI, and then later the value of that variable is changed, the editing logic function is not triggered. The Spur Gear feature uses the the editing logic function to re-calculate the pitchCircleDiameter input when the numTeeth or module inputs change, and re-calculate the the module input if the PitchCircleDiameter changes (because PitchDiameter=Module*numTeeth). So when I use a variable to set the module value in the UI, and then change the variable value, the pitchCircleDiameter is not correctly updated. I can see that the module change is applied because it also affects the length of the gear teeth and I can see them change, but the gear doesn't correctly increase in diameter.
2. If I do set some of these UI values with variables and/or configuration variables, and then do something that does trigger the editing logic function like change something else in the UI, the re-calculation logic it uses overwrites all those variables with the re-calculated values. This is pretty obvious when I encountered it, but it does complicate trying to drive it with configuration variables. It's particularly complicated because the config UI actually has 3 different ways to configure the module value using different settings that hide/unhide depending on a gearInputType dropdown selection, and all of these are recalculated when the editing logic function is triggered.
I'm not sure if the editing logic function not being triggered for variable changes is a bug or not, but even if this was changed it would just make problem 2. above worse, making it even harder to use and drive this with configuration variables. So I'm inclined to see it as a convenient feature :-)
I'm going to have a bit more of a play with this and see if I can figure out how to make it work. Failing that, I'm going to fix the featurescript, because I've already done some other work on improving it.
Editing logic only triggers when the feature dialog is open and the user modifies inputs of the feature (or manipulators).
Editing logic is best at setting default parameters. The calculation of teeth/pitch/diameter should take place in the main body, editing logic removed, and then the user is given an option of which combination of parameters to use, using if/else in the predicate to show/hide the appropriate fields.
Editing logic can solve a lot of tricky problems, but it has its downsides.
I'd love to see an option to make the editing logic function trigger on regen - it would solve some of these types of headaches.
Custom FeatureScript and Onshape Integrated Applications