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.
Help with LOFT_DIRECTION_ERROR - opLoft
I have two identical spirals in my part studio, and I am trying to connect them with a simple loft, however when I try to use opLoft
I get hit with the error LOFT_DIRECTION_ERROR
. Below is the code:
FeatureScript 2455; import(path : "onshape/std/geometry.fs", version : "2455.0"); annotation { "Feature Type Name" : "Torsion Spring", "Feature Type Description" : "" } export const torsionSpring = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type annotation { "Name" : "Plane", "Filter" : GeometryType.PLANE, "MaxNumberOfPicks" : 1 } definition.plane is Query; annotation { "Name" : "Diameter" } isLength(definition.diameter, NONNEGATIVE_LENGTH_BOUNDS); annotation { "Name" : "Mate Size" } isLength(definition.mateSize, NONNEGATIVE_LENGTH_BOUNDS); annotation { "Name" : "Revolutions" } isInteger(definition.revolutions, POSITIVE_COUNT_BOUNDS); } { const radius = definition.diameter / 2; const mateRadius = definition.mateSize / 2; const turns = definition.revolutions; const l = 3.5; opHelix(context, id + "helix1", { "direction" : vector(0, 0, 1), "axisStart" : vector(0, 0, 0) * inch, "startPoint" : vector(radius, 0, 0), "interval" : [0, turns], "clockwise" : true, "helicalPitch" : (l / turns) * centimeter, "spiralPitch" : (radius - mateRadius) / turns * -1 }); // Project with projectCurves var spiral = projectCurves(context, id + "projectCurves1", { "curveProjectionType" : CurveProjectionType.CURVE_TO_FACE, "projectionType" : ProjectionType.NORMAL_TO_TARGET, "dropTools" : qCreatedBy(id + "helix1", EntityType.EDGE), "targets" : qCreatedBy(makeId("Top"), EntityType.FACE)//qCreatedBy(mS_ID, EntityType.FACE) //qCreatedBy(makeId("Top"), EntityType.FACE) }); // Create coppy spiral opPattern(context, id + "pattern1", { "entities" : qCreatedBy(id + "projectCurves1", EntityType.BODY), "transforms" : [transform(vector(0, 0, 1) * centimeter)], "instanceNames" : ["projectCurves2"] }); var subQueries = [ qCreatedBy(id + "projectCurves1", EntityType.BODY), qCreatedBy(id + "pattern1", EntityType.BODY) ]; //connect spirals opLoft(context, id + "loft1", { "bodyType" : ToolBodyType.SURFACE, "profileSubqueries" : subQueries }); });
Document:
https://cad.onshape.com/documents/10f6e24327ebfd7f615a4879/w/8c73a0b1a748ca34b5a118fa/e/95253a01783f14b76e00837d
Thanks for any help in advance 😁
Best Answer
-
Jed_Yeiser Member Posts: 37 PRO
Hey jensen_brightman, the only 'issue' I can find here shouldn't be an issue. Those with more featurescript knowledge may be able to chime in to explain the root cause. (it's worth noting that the code in the document you posted does not match the code in your comment - document code had the same query repeated twice for var subQueries, and did not specify a toolBodyType in opLoft).
Your queries refer to bodies, not edges. I'd ASSUME that specifying a surface loft and providing opLoft with wire bodies wouldn't cause issues - however, changing the queries to edges solves the issue. Queries can be… confusing. I often struggle to get a bit of code working as expected, only to find that my queries were incorrect.
var subQueries = [ qCreatedBy(id + "projectCurves1", EntityType.EDGE), qCreatedBy(id + "pattern1", EntityType.EDGE) ];
I've copied your document and made the changes I outlined above (as well as deleting the seed helix) here. https://cad.onshape.com/documents/ab6adb0dcda4565d146c0ef2/w/5045c0e00ead73055b4488f2/e/c4897d8d9daeade5de4db023?renderMode=0&uiState=66e68f8a2d17f11d80823141
I hope that helps!
0
Answers
Hey jensen_brightman, the only 'issue' I can find here shouldn't be an issue. Those with more featurescript knowledge may be able to chime in to explain the root cause. (it's worth noting that the code in the document you posted does not match the code in your comment - document code had the same query repeated twice for var subQueries, and did not specify a toolBodyType in opLoft).
Your queries refer to bodies, not edges. I'd ASSUME that specifying a surface loft and providing opLoft with wire bodies wouldn't cause issues - however, changing the queries to edges solves the issue. Queries can be… confusing. I often struggle to get a bit of code working as expected, only to find that my queries were incorrect.
var subQueries = [ qCreatedBy(id + "projectCurves1", EntityType.EDGE), qCreatedBy(id + "pattern1", EntityType.EDGE) ];
I've copied your document and made the changes I outlined above (as well as deleting the seed helix) here. https://cad.onshape.com/documents/ab6adb0dcda4565d146c0ef2/w/5045c0e00ead73055b4488f2/e/c4897d8d9daeade5de4db023?renderMode=0&uiState=66e68f8a2d17f11d80823141
I hope that helps!