How to use Move boundary in FeatureScript - opMoveBoundary()

MichaelPascoe
MichaelPascoe Member Posts: 2,965 PRO
edited April 2024 in FeatureScript
I was having trouble finding how to use the Move boundary within FeatureScript. There is no OpMoveBoundary or OpExtend like you would expect. Here is how you can do it:

Import the extend FS from Onshapes STD at the start of your project.
// For move boundary
import(path : "12312312345abcabcabcdeff/6509fdce3abecacec8f38b8a/cffdc47ca3931d4c4d41ee51", version : "0e66a19d0a986e71c5d22df8");

Next, define the definition for the extend surface and call the function:
// Extend ends using move boundary
const extendSurfaceDefinitionLeft = {
     "entities" : leftEnd, // Query
     "tangentPropagation" : false, // Boolean
     "endCondition" : ExtendBoundingType.BLIND, // ExtendBoundingType
     "extendDistance" : definition.extensionLeft, // Length
     "oppositeDirection" : false, // Boolean
     "targetPart" : qNothing(), // Query
     "targetFace" : qNothing(), // Query
     "targetVertex" : qNothing(), // Query
     "maintainCurvature" : false // Boolean
};

extendSurface(context, id + "leftEndExtend", extendSurfaceDefinitionLeft);


RENDERCAD - Photorealistic product rendering.
CADSharp - Professional CAD + software consulting.

▚▞▚▞▚▞▚▞▚

Comments

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,965 PRO
    Or... Just use opExtendSheetBody() 
     :D Thanks @Jacob_Corder! 

    RENDERCAD - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚
  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭

    And of-coarse if you're trimming edges back you'll need to use "opEdgeChange" you'll have to figure out how to use it by studying the "Extend" tab in std library source: https://cad.onshape.com/documents/02e253006c3b752eb13303a7/w/7b120b69b752b11fdbbb09dc/e/4b13fb3967e27f942c8ae475

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭
    edited December 2024

    Actually I'll go one better: I've made an opTrimEdges function in case anyone wants to trim back the boundaries of a sheet/surface:

    export function opTrimEdges(context is Context, id is Id, surfacesOrEdges is Query, trimDistance is ValueWithUnits, tangentPropegation is boolean)
    {
        //get edges and track them
        var selectedEdges = qEntityFilter(surfacesOrEdges, EntityType.EDGE);
        if (tangentPropegation)
        {
            selectedEdges = qUnion([selectedEdges, qTangentConnectedEdges(selectedEdges)]);
        }
        var allEdges = qEdgeTopologyFilter(qUnion([selectedEdges, qOwnedByBody(surfacesOrEdges, EntityType.EDGE)]), EdgeTopology.ONE_SIDED);
    
        var trackedEdges = [];
        for (var edge in evaluateQuery(context, allEdges))
        {
            trackedEdges = append(trackedEdges, qUnion([edge, startTracking(context, edge)]));
        }
        
        //Make array to use in edge trimming
        var edgeChangeOptions = [];
        for (var i = 0; i < size(trackedEdges); i += 1)
        {
            var edge = trackedEdges[i];
            edgeChangeOptions = append(edgeChangeOptions, { "edge" : edge,
                        "face" : qAdjacent(edge, AdjacencyType.EDGE, EntityType.FACE),
                        "offset" : trimDistance});
        }
        if (edgeChangeOptions == [])
        {
            throw regenError(ErrorStringEnum.EXTEND_SHEET_BODY_NO_BODY, ["entities"]);
        }
        
        //trim edges
            try silent
        {
            opEdgeChange(context, id + "edgeTrim", { "edgeChangeOptions" : edgeChangeOptions });
        }
        catch
        {
            var edgesToTrim = [];
            for (var i = 0; i < size(edgeChangeOptions); i += 1)
            {
                edgesToTrim = append(edgesToTrim, edgeChangeOptions[i].edge);
            }
            setErrorEntities(context, id, { "entities" : qUnion(edgesToTrim) });
            throw regenError(ErrorStringEnum.TRIM_FAILED);
        }
    

    }

    Two more things to note that I've learnt is:

    1. In std library the tab that holds the "moveBoundary" feature is called "extend" which is silly
    2. You can refer to standard library tabs buy in this format "import(path : "onshape/std/##tab name##", version : "2543.0");" for example: import(path : "onshape/std/extend.fs", version : "2543.0"); and that way you can make sure you use the latest ver.