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.

Feature script for filling in missing faces to fix faulty topology.

Hello,

I want to create a feature script that let's me select bodies with missing faces (faulty topology), i.e. surfaces, and automatically have these missing faces filled. So far I came up with the following feature script:

  • https://cad.onshape.com/documents/7636bb7733c1c2c502d0810b/w/c9b207aa5d8f3be062fdb8ac/e/65be33586f5da95b0cc2559f

I'm able to create the missing faces just fine, but unfortunately I'm struggling at combining the creates faces with the existing surfaces to get body. Any help would be greatly appreciated.

Answers

  • MichaelPascoeMichaelPascoe Member Posts: 2,110 PRO
    edited February 21

    Try something like this instead. Note this is not optimized, i simply took your code and made it work. There are better and are more shorthand ways to do all of this, but this should get you going:

    import(path : "onshape/std/common.fs", version : "2581.0");
    
    annotation { "Feature Type Name" : "My Feature", "Feature Type Description" : "" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Surfaces", "Filter" : EntityType.BODY && BodyType.SHEET }
            definition.surfaces is Query;
        }
        {
            const evSurfaces = evaluateQuery(context, definition.surfaces);
            const surfaceCount = size(evSurfaces);
    
            for (var i = 0; i < surfaceCount; i += 1)
            {
                const thisSurface = evSurfaces[i];
                const boundaryEdges = qEdgeTopologyFilter(qOwnedByBody(thisSurface, EntityType.EDGE), EdgeTopology.LAMINAR);
                const evEdges = evaluateQuery(context, boundaryEdges);
                const edgeCount = size(evEdges);
                var processedEdges = new box([]);
    
                for (var k = 0; k < edgeCount; k += 1)
                {
                    const thisEdge = evEdges[k];
    
                    // perform operations with the entity
                    if (isIn(thisEdge, processedEdges[]))
                    {
                        return;
                    }
    
                    var loop = qLoopEdges(thisEdge);
    
                    try
                    {
                        var idFillSurface = id + "fillSurface1" + i + k;
                        opFillSurface(context, idFillSurface, {
                                    "edgesG0" : loop
                                });
    
                        var idBoolean = id + "boolean1" + i + k;
                        opBoolean(context, idBoolean, {
                                    "tools" : qUnion(thisSurface, qCreatedBy(idFillSurface, EntityType.BODY)),
                                    "operationType" : BooleanOperationType.UNION,
                                    "makeSolid" : true,
                                });
                    }
    
                    processedEdges[] = concatenateArrays([processedEdges[], evaluateQuery(context, loop)]);
                }
            }
        });
    

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • MichaelPascoeMichaelPascoe Member Posts: 2,110 PRO
    edited February 21

    Don't forget to complete Onshape's FeatureScript Fundamentals Course.

    Also check out the CADSharp FeatureScript Course


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
Sign In or Register to comment.