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.

The case of editing logic function usage.

konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,018 ✭✭✭✭✭
edited August 27 in FeatureScript
Im' trying to automate the process of getting mate connectors owned by selected bodies into the list input ( with options to define some associated orientation data from enum parameter). But seems like when editing logic function is set the feature treats my attempt to edit list input parameter as a signal to refresh input field. Am I doing something wrong?
The editing logic function looks like this:

export function modifyMCArr(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map) returns map
    var partsMCQueries = qMateConnectorsOfParts(oldDefinition.parts)->qOwnedByBody(EntityType.VERTEX);

    if (isCreating/* && !specifiedParameters.MCs*/)
        definition.MCs = [];
        for (var MC in evaluateQuery(context, partsMCQueries))
            definition.MCs = append(definition.MCs, { "query" : MC, "orientation" : CoordSystemOrientation.ZERO });
        return definition;



  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 1,887 PRO
    Did you mean to use 'oldDefinition' where you check the parts?
    Also, if isCreating is false, your function does not live up to its promise of always returning a `map`.
    MB - I make FeatureScripts: View FeatureScripts
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    Anything you return from an editing logic function will be used the new value. If you want the result after your change to keep some of the old values inside the old definition.MCs, you will need to insert those values onto the return value somehow.

    This involves your function settling on an answer to what happens when the sizes or content of definition.MCs and partsMCQueries differ.
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,018 ✭✭✭✭✭
    edited August 28
    @kevin_o_toole_1 I think I don't qute understand from the documentation what triggers edit logic function evaluation? is it any change in definition while feature dialog is open? and if the answer is "yes" what state of input is treated as oldDefinition and definition? before and after the edit?
    @MBartlett21 I was just trying to workout the case when feature is just created and actually can't advance any farther.
    upd: So the right test to find out if the certain input field is edited by user during feature creation seem to be pretty tricky
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    edited August 28
    Correct. Editing logic is called after every user change. oldDefinition contains the parameter values before the change, definition contains the parameter values after the change.

    If you want your editing logic to only run when a certain parameter changes, you can simply add logic like
    if (oldDefinition.parts != definition.parts)
       // change definition.MCs and return modified version

Sign In or Register to comment.