Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

How to use Move boundary in FeatureScript - opMoveBoundary()

MichaelPascoeMichaelPascoe Member Posts: 2,018 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);


Learn more about the Gospel of Christ  ( Here )

CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴

Comments

  • MichaelPascoeMichaelPascoe Member Posts: 2,018 PRO
    Or... Just use opExtendSheetBody() 
     :D Thanks @Jacob_Corder

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • christopher_dziubachristopher_dziuba Member Posts: 80 ✭✭

    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_dziubachristopher_dziuba Member Posts: 80 ✭✭
    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.

Sign In or Register to comment.