Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
edited April 2017 in FeatureScript
Do editing logic functions work with enums? If so, how do I implement it?

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!

Best Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,307
    edited April 2017 Answer ✓
    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, EMEAI

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    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 Inc
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    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 Inc
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,307
    Also, you need isCreating in the logic function parameters if you want this to work on existing features.
    Senior Director, Technical Services, EMEAI
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    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 Inc
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    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 Inc
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    Okay, now there is another problem. The value is now fixed, as soon as I change it, it changes itself back to 64mm
    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!
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,307
    edited April 2017 Answer ✓
    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, EMEAI
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭
    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!
Sign In or Register to comment.