Create a sketch and get all intersection curve with all the parts.

CHUNG_MING_CHANG
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)

  1. how to create sketch to get all intersection curves
  2. 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

Comments

  • CHUNG_MING_CHANG
    CHUNG_MING_CHANG Member Posts: 8 PRO

    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:

    1. Sketch generated by FS, can't be used in Assembly. Is this fixed or any way to do it?
    2. How to project all the curves to sketch?
  • CHUNG_MING_CHANG
    CHUNG_MING_CHANG Member Posts: 8 PRO

    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:

    1. two box →8 curves (if I select 2 parts, correct, but default will generate 10 curves, some duplicate)
      1. Curve 1 and Curve 3 are the same
    2. How to create sketch with projection these curves?
    image.png