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.

Possible Editing Logic bug with Array parameters

George_AndersonGeorge_Anderson Member Posts: 71 ✭✭
edited April 2021 in FeatureScript
[Only not posting to support because I first want some community feedback about whether I'm using Editing Logic incorrectly]
MWE:

My EL function is modifying feature parameters based on whether any entity is selected.
The bug is reproduced by:
1) In the TEST function, add a single operation.
2) Under entities, select the *midpoint* of the single edge in the scene (bug doesn't happen if you select the endpoints)
It will show up as a "missing item".
Curiously, when I do the same thing outside of the array parameters, I don't have this bug.
More curiously, this bug only happens when selecting the midpoint of the edge, not the endpoints.


Tagged:

Comments

  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    Evan and I ran into this bug a little while ago, as documented in this thread. It appears that updating an internal array parameter using the editing logic function causes certain types of internal array query selections to fail or become missing - in Evan's case, it was implicit mate connectors (i.e. those selected using the mate connector button in an array internal query parameter which allows BodyType.MATE_CONNECTOR), but I guess it also causes mid points, and probably some other entities nobody's discovered yet, to fail as well. Unfortunately, I don't really know of any work arounds. I would recommend submitting a ticket to support. If you do decide to submit a ticket, I would recommend also mentioning that this causes implicit mates to fail as well. 
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    A lot of magic happens inside editing logic function If you performing some data wrapping/incapsulating operations under data types with type tags like queries or enums. All in all seems like during its evaluation at some moment it looses visibility of either part stuio or feature studio namespace, and thus later it's unable to recognize whether it is arbitary map or query, or enum entry vs string. Try to somehow restore type tag of your data before restoring it to definition
  • George_AndersonGeorge_Anderson Member Posts: 71 ✭✭
    @konstantin_shiriazdanov Thanks, I gave it a bit of a try, but it's slightly deeper than my understanding of the type tags. There's a new interesting twist. If I first select an endpoint, and then add a midpoint to the selection, it's happy with the midpoint. Additionally, I can tell that it some cases the bad query is getting converted to an array with one qNothing element, while in others, it's just becoming an empty array. I think I need to let someone else take this further, but these are some tantalizing clues!

    @Alex_Kempen I submitted a ticket and referenced your thread as well.
  • George_AndersonGeorge_Anderson Member Posts: 71 ✭✭
    Actually, thanks to @konstantin_shiriazdanov 's clues, I just confirmed that what breaks it is evaluating the entity query inside the array parameter.
  • George_AndersonGeorge_Anderson Member Posts: 71 ✭✭
    I had no idea that evaluating a query had the capacity to modify some kind of underlying state. Does it modify the context?
  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    edited April 2021
    George, the reason it works if you select another point first is because you only update an internal array parameter when the size of the query goes from 0 to 1.
    The specific bug you're seeing can be summarized as follows:
    If any parameter inside an array parameter is changed via editing logic, then any selected implicit mate connectors and/or midpoints of query parameters inside array parameters immediately fail. 

    Evaluating the query does not affect whether it fails or not. You can see this if you add a condition like the following to your editing logic function:
    if (definition.enableArrayParameter == true)
        definition.arrayParamter[0].booleanParameter = !definition.arrayParameter[0].booleanParameter;
    When definition.enableArrayParameter is true, making any change will immediately cause any selected mate connectors and midpoints to fail, even if you aren't evaluating said internal query parameter in your editing logic function. If you disable definition.enableArrayParameter, then you'll be able to select implicit mate connectors and midpoints once again without issue.
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • George_AndersonGeorge_Anderson Member Posts: 71 ✭✭
    @Alex_Kempen Good catch. Indeed that's the problem, not the evaluation. So that means there's probably some remapping craziness going on in the back-end, when OnShape detects that anything has changed.
  • lougallolougallo Member, Moderator, Onshape Employees, Developers, csevp Posts: 2,005
    This bug as been logged. Thanks everyone.
    Lou Gallo / PD/UX - Support - Community / Onshape, Inc.
  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    @lougallo, it also appears that this bug affects manipulatorChangeFunctions - updating an item inside an array parameter causes any selected implicit mate connectors to become a "Part of mate connector". Notably, however, this behavior is different than when you change an internal array parameter using editing logic, since that causes mate connectors to fail entirely. 
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    @Alex_Kempen for mate connector you need to assign to the field not an MC body query, but rather vertex query qEntityFilter(mcBodyQuery, EntityType.VERTEX)
  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    @konstantin_shiriazdanov, I'm not sure I understand your comment. Mate Connectors are a special type of point body, so they have EntityType.BODY and BodyType.MATE_CONNECTOR. But I think that's a bit moot, since my original comment was simply pointing out that updating any parameter inside an array parameter using a manipulator change function causes any mates selected inside array parameters to break.

    Code wise, it looks something like this:
    precondition {
        annotation { "Name" : "Widgets", "Item name" : "Widget", "Item label template" : "#myParameter" }
        definition.myWidgets is array;
        for (var widget in definition.myWidgets)
        {
            annotation { "Name" : "My boolean" }
            widget.myBoolean is boolean;
            annotation { "Name" : My query", "Filter" : EntityType.VERTEX && SketchObject.YES || BodyType.MATE_CONNECTOR }
            widget.myQuery is Query;
        }
    }
    
    export function mountManipulatorChange(context is Context, definition is map, newManipulators is map) returns map
    {
        for (var i = 0; i < size(definition.myWidgets); i += 1)
        {
            definition.myWidgets[i].myBoolean = !definition.myWidgets[i].myBoolean; // causes mate connectors selected with widget.myQuery to break
        }
        return definition;
    }
    
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    I have feature where I was getting mate connectors via editing logic, and if I was filling field with mc query as a body it was displayed in query field of UI as "body of Mate Connector" , but when I passed qOwnedByBody(mcBodyQuery, EntityType.VERTEX) it displayed in UI like normal "Mate Connector". So this at least can explain what had possibly changed in definition interpretation after manipulator change triggered.
    But I also experiencing a lot of strangeness in working with array parameters: for example if you just change an order of fields inside arr parameter in definition, then arr parameter will be reseted to empty array when you open the feature dialog. Another strange case is when you trying to restore arr param content from inside editing logic with some fields, that where not displayed in oldDefinition (though they are decleared) That can also cause arr param to be reset to empty array after feature dialog is open.
Sign In or Register to comment.