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.
Create a sketch and get all intersection curve with all the parts.
CHUNG_MING_CHANG
Member Posts: 8 PRO
Dear all,
The CAD process I'm doing now is using "intersection curve" to get all the curves, then create a sketch and project them.
("intersection curve" and project with USE, I can use mouse to select a window.)
I want to create a FS, maybe there is another efficiency way to do this. (The input is a selected Plane)
- how to create sketch to get all intersection curves
- how to use for loop with all part.
If there is a similar FS could be a reference, please also provide and I could study it.
Thanks all
Steven
0
Comments
Update: Simplify, using body to do intersect.
FeatureScript 2737;
import(path : "onshape/std/common.fs", version : "2737.0");
annotation { "Feature Type Name" : "Section Curves", "Feature Type Description" : "Intersect a plane with all faces" }
export const SectionCurves = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// Pick Plane
annotation { "Name" : "Cut Plane", "Filter" : EntityType.FACE && GeometryType.PLANE, "MaxNumberOfPicks" : 1 }
definition.cutPlane is Query;
// Pick Part, default pick ALL annotation { "Name" : "Scope (optional)", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 10 } definition.scope is Query; } { var targetBody = (definition.scope != undefined && !isQueryEmpty(context, definition.scope)) ? qOwnedByBody(definition.scope, EntityType.BODY) // 指定 Part → 取出所有面 :qAllModifiableSolidBodiesNoMesh(); opIntersectFaces(context, id + "intersectFaces1", { "tools" : definition.cutPlane, "targets" : targetBody }); var PLN1 = evPlane(context, { "face" : definition.cutPlane }); // definition.CutPln is a Query, not a plane var sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : PLN1 }); skSolve(sketch1); });Question:
FeatureScript 2737;
import(path : "onshape/std/common.fs", version : "2737.0");
annotation { "Feature Type Name" : "Section Curves", "Feature Type Description" : "Intersect a plane with all faces" }
export const SectionCurves = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// pick plane
annotation { "Name" : "Cut Plane", "Filter" : EntityType.FACE && GeometryType.PLANE, "MaxNumberOfPicks" : 1 }
definition.cutPlane is Query;
// option, default all parts annotation { "Name" : "Scope (optional)", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 10 } definition.scope is Query; } { var targetFaces = (definition.scope != undefined && !isQueryEmpty(context, definition.scope)) ? qOwnedByBody(definition.scope, EntityType.FACE) // 指定 Part → 取出所有面 :qOwnedByBody(qEverything(EntityType.BODY), EntityType.FACE); //: qEverything(EntityType.FACE); // 全工作室 // 避免把自己這個平面也放進 targets(平面和自己相交會退化) targetFaces = qSubtraction(targetFaces, definition.cutPlane); targetFaces = qSubtraction(targetFaces, qCreatedBy(makeId("Right"), EntityType.FACE)); targetFaces = qSubtraction(targetFaces, qCreatedBy(makeId("Front"), EntityType.FACE)); targetFaces = qSubtraction(targetFaces, qCreatedBy(makeId("Top"), EntityType.FACE)); //qCreatedBy(makeId("Right"), EntityType.FACE) // 呼叫標準 operation:Plane × Faces → Curves opIntersectFaces(context, id + "ic", { "tools" : definition.cutPlane, "targets" : targetFaces }); // 交線結果會是新產生的 edges (Curves),可以用 qCreatedBy 抓出來 var resultEdges = qCreatedBy(id + "ic", EntityType.EDGE); // 也可以在這裡輸出 log 看看 println("Created curves: " ~ size(evaluateQuery(context, resultEdges))); // Define the function's action var PLN1 = evPlane(context, { "face" : definition.cutPlane }); // definition.CutPln is a Query, not a plane var sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : PLN1 }); skSolve(sketch1); });I debug from GhatGPT, and now it could generate the curves.
Question: