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.
Feedback into UI panel
Lee_Hesketh
Member, Developers Posts: 148 ✭✭✭
Hello, is it possible to use a calculated value as a default in the UI panel and have that value displayed?
Thanks
Lee Hesketh
Thanks
Lee Hesketh
There are 10 types of people in the world. Those who know binary, those who don't and those who didn't expect base 3!
Tagged:
0
Best Answers
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215Yes, using the editing logic function. See our modifyFillet feature for an example: https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/9fa139fb0be24611874fa080Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215Ok, I see -- it's a fair bit of code to compute it and you don't want to duplicate all of it. And a function only returns one argument. The way I'd do it is to write the initial computations (at least up to part_wide) be in a function that returns a map. Something like:
<br>function initialComputations(context, id, definition) returns map<br>{<br> var result = {};<br><br> ...<br> result.intFace1 = qNthElement(result.intFaces, 1);<br> ...<br> result.part_wide = evDistance(...);<br> ...<br><br> return result;<br>}<br>
and call it from both places and use the data in the map.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5 -
NeilCooke Moderator, Onshape Employees Posts: 5,714var comps = initialComputations(context,id,definition);
var intface1 = comps.intface1;Senior Director, Technical Services, EMEAI5
Answers
Notice that the length parameter is set to a string -- that sets the expression in the dialog. If you want to set it to a value, you'd do something like
instead of
e.g. definition.part_width = 2*inch;
I think it would be better if I just give you the file so I you can see how I have come to getting part_wide.
The problem is that the other variables need to calculate part_width are also need in the rest of the script. Is there a way for the script have more arguments and each one can be extracted for use later on?
https://cad.onshape.com/documents/580b256ade95e210af0261d8/w/1d22e17d9b07548059b7b311/e/971ebd1bc44955a2e5997b6d
"Mortice and Tenon"
and call it from both places and use the data in the map.
var intface1 = comps.intface1;
So If I have all of the data in the initialComputations stored in result{}, going back to my OP, how would I display part_wide in the UI panel? Could I just use @ilya_baran's editingLogicExample code and add another parameter i.e.
But there is an error when I call initialComputations in the setDefault function. It says variable definition not found.
What am I doing wrong?
Attempt to dereference non-container undefined. Could this be a scope issue?
I ran the whole code, and it sort of works. It doesn't show the calculated width, it's still the default 25mm. I tried running a new instance of it, still 25mm. I looked at the activity log and there were errors. The strange thing is that I debugged all the variables in InitialComputations in the main body and they are correct. When debugging part_wide/3, I get the correct value as shown. But the activity log shows errors when calling qEdgeAdjacent. What am I doing wrong?
You may need to pass the query into your function and/or editLogicFunction - you could add it to the definition map and pass it that way.