Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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_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:
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 } );
}
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,211Sketch ids only need to be unique within the sketch, so they can be created however you want (as long as it's letters and numbers and a few special characters). Using ~ is good for sketch ids.
I don't think feature ids are ever treated or passed around as strings -- the typical form isid + "string"
but the operator + is overloaded to append to the array underneath. I also don't know a use case for converting feature ids to strings except for debugging -- and then you can pass it to print or use"" ~ featureId
to make a human string.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
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: 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.
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.
I don't think feature ids are ever treated or passed around as strings -- the typical form is
id + "string"
but the operator + is overloaded to append to the array underneath. I also don't know a use case for converting feature ids to strings except for debugging -- and then you can pass it to print or use"" ~ featureId
to make a human string.