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.

Why does this editing Logic query not work

dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
I have a feature that accepts both an edge and a face.  My goal is to use an editing logic function to pre-populate the face that contains the provide edge, if there is one.

In the example below, you can see that the editing logic does select a face. But then there is an error assigning it to the definition: "Editing logic result Parameter "face" does not satisfy spec. But it should, because it is clearly a query.

What am I missing?




Complete code:

FeatureScript 370;
import(path : "onshape/std/geometry.fs", version : "370.0");

annotation { "Feature Type Name" : "My Feature", "Editing Logic Function" : "editLogic" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {        
        annotation { "Name" : "EDGE","Filter" : EntityType.EDGE }
        definition.edge is Query; 
                        
        annotation { "Name" : "Surface","Filter" : EntityType.FACE }
        definition.face is Query;         
    }
    {
        debug(context,definition.face);    
    });

//You can also add a boolean argument to the cPlaneLogic function as the last argument 
//(this is currently undocumented but it makes the logic function run when the feature is edited, not just created).
export function editLogic(context is Context, id is Id, oldDefinition is map, definition is map,
                              isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map {
    
    if (oldDefinition == {} ){

        var pnt = evEdgeTangentLine(context, {
                "edge" : definition.edge,
                "parameter" : 0
        });
        
        var p = qNthElement(qContainsPoint(qEverything(EntityType.FACE),pnt.origin),1);
        debug(context,p);
        definition.face = p;
            
    }
    return definition;
    
}

Best Answers

Answers

  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    Just looking at our server code and not trying your code, you need to return a qUnion() result even if there is only one thing in the query.
  • dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    Thanks guys, that works. Never would have guessed, thanks for the help!  
  • dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    For those who read this in the future, I had tried something similar, which also didn't work:

    qUnion([evaluateQuery(context, p)])
    Note in the above case the array syntax, which is the syntax most commonly used with qUnion.
    If you use the array version, you
    will get the same assignment error as above. In this case, you need to use the form without the array syntax, which I would never guess.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Yeah, that makes sense. The tricky thing is that evaluateQuery() returns an array, so that qUnion would be constructed with an array of arrays, rather than an array of Queries.

  • dave_cowdendave_cowden Member, Developers Posts: 470 ✭✭✭
    alright, thanks!
Sign In or Register to comment.