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.
Do editing logic functions work with enums?
Lee_Hesketh
Member, Developers Posts: 148 ✭✭✭
Do editing logic functions work with enums? If so, how do I implement it?
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!
0
Best Answers
-
Could it be as simple as the misspelling of "length"?Senior Director, Technical Services, EMEA6
-
Try something like:
if(changedDefinition.myEnum == myEnum.ONE)<br>changedDefinition.length = 1*inch; <br>if(changedDefinition.myEnum == myEnum.TWO)<br>changedDefinition.length = 2*inch; <br>}<br>return changedDefinition;</code><h2><pre class="CodeBlock"><code>if(oldDefinition.myEnum != changedDefinition.myEnum)<br><code> {<br>
Senior Director, Technical Services, EMEA2
Answers
-
They do -- as with the other parameters, you set the changed enum in the returned definition of the editing logic function. What is the difficulty you are running into?Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
Well, I am checking if the enum is a certain value and setting another value to an arbitrary value.
export function defaults(context is Context,id is Id, oldDefinition is map, changedDefinition is map) returns map { if(oldDefinition.myEnum==myEnum.ONE) { changedDefinition.legnth = 1*inch; } return changedDefinition; }But nothing happens and don't know why.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!0 -
I don't see an issue here. Does the error pane show anything? Sharing the document may help.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
Could it be as simple as the misspelling of "length"?Senior Director, Technical Services, EMEA6
-
Also, you need isCreating in the logic function parameters if you want this to work on existing features.Senior Director, Technical Services, EMEA0
-
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!0
-
It works if I change the value after the if statements, just not in them.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!0
-
I fixed it, damn you misspelling!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!0
-
Now there is another error, for some reason, the value set if the enum is TOP should be 64 and 128 if it is BOTTOM. However, they are switched. I haven't changed this in the code. Why is it doing this?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!0
-
It's because you're checking oldDefinition instead of newDefinition. It's checking where you're switching *from*.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
Ah, so would I just change it to newDefinition?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!0
-
Yes -- check the value in newDefinition. oldDefinition is primarily there to see what's changed, not what a parameter has changed *to*.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
Okay, now there is another problem. The value is now fixed, as soon as I change it, it changes itself back to 64mmThere are 10 types of people in the world. Those who know binary, those who don't and those who didn't expect base 3!0
-
Try something like:
if(changedDefinition.myEnum == myEnum.ONE)<br>changedDefinition.length = 1*inch; <br>if(changedDefinition.myEnum == myEnum.TWO)<br>changedDefinition.length = 2*inch; <br>}<br>return changedDefinition;</code><h2><pre class="CodeBlock"><code>if(oldDefinition.myEnum != changedDefinition.myEnum)<br><code> {<br>
Senior Director, Technical Services, EMEA2 -
Thank you so much!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!0


