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.

Error down in the script creates odd 'precondition' message?

dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
Im afraid i need some help. 

I'm trying to create a feature, and when I run the example, I get an error that reads:
"precondition" failed-- but then the trace points to code in the body.

Here is the document ID ( shared with Onshape support ):
https://cad.onshape.com/documents/4789a5ead96249ca887238e9/w/f87b9ae18ede4764b47922af/e/c683e9bc17f249d3bf5b4c07

Im not sure what i'm doing wrong: i need a better error message to get further.

On another note, i'm clearly not understanding Ids correctly.  I dont know whether the ID passed into the newSketchOnPlane function should be the ID of the parent feature, or a newly created id.

Could I get some advice on how to proceed? 
I've pasted the code below, but you can see the error message condition in my part studio link above:

function createTorus(context, parentId, id, line, point, minorRadius, majorRadius){    
    
    //line has properties origin and direction ( both vectors )
    //point is  vector ( presumably on the line )
    
    var profilePlaneXAxis = perpendicularVector(line.direction);
    var profilePlaneZAxis = cross(profilePlaneXAxis,line.direction);
    
    //create sketch plane perpendicular to this one, and a sketch on it
    var profilePlane = plane(point,profilePlaneZAxis, profilePlaneXAxis);
    print("input id =" ~ id ~ "\n");
    var profileSketchId = id ~ "-profilesketch";
    _debug(context,"profileSketchId =",profileSketchId);
    _debug(context,"profilePlane =",profilePlane);
     //is the ID here supposed to be the parent ID, or a new ID? if so, how do i create one? //i got an error when i tried putting profileSketchId here
    var profileSketch = newSketchOnPlane(context,parentId, { sketchPlane: profilePlane } );
    skCircle(profileSketch,id ~ "-profilecircle", { center: vector(majorRadius,0) , radius: minorRadius * inch } );
    //skSetInitialGuess ()? 
    skSolve(profileSketch);
    
    
    //sweep to create the torus
    opRevolve(context,id ~ "-oRing",{axis: line , entities: qSketchRegion(profileSketchId ,false) , angleForward: 2* PI } );
}


Best Answer

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    I think the problem is with the center: vector(majorRadius,0) makes a vector where the first component is (probably) a length and the second is a scalar.  Both coordinates should have length units.  We're working on improving the precondition-failed error messages.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    OK thanks I will try that. I definitely wouldn't ever have figured that out! Thanks as always for the help.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    On Ids: Sketch entity ids are just strings, but feature ids are hierarchical arrays of strings. The Id array helps you and Onshape keep track of what feature geometry was made for what purpose in a tree-like structure. It's important to remember that a new sketch is a feature, but individual sketch entities are not (just like in normal Onshape modeling).

    To make a sub-id of the form ["featureId", "operationDescription"], the overloaded operator is +, not ~, so the Id you want to create for the sketch is probably:
    id + "profileSketch"
    
     On preconditions: The precondition that failed wasn't one you wrote, it was one within the Standard Library. To diagnose that failure, the best strategy, currently, is to find the line in std that failed, go to the std document, find the Feature Studio and line of failure, and backtrack from there.

    As Ilya said, we'll have better messages for precondition failures soon, and and we're working on functional links to external documents from the stacktrace too.

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    alright, thanks for that answer.  so the ID passed into my feature is an 'array-like' feature id, and i should be using array-like feature ids everywhere except inside of the sketch, where i should use string ones. right?

    is there  a standard way to create sketch entity ids? can they be arbitrary or do they need to be globally unique? And, is there a standard one-liner to go from an 'array-like' ID to a string one?

    I'm confused somewhat because when i look at FS code generated by Part Studio, the IDs passed around appear to be strings all the time. 
Sign In or Register to comment.