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.

Options

FeatureScript smooth edges

MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
in FeatureScript, I would like to make my own error message instead of the one generated by opFillet();.

I have written this function to fillet all the edges in a model except the ones that are specified.

https://cad.onshape.com/documents/b7252b2d8824c81fa19efffe/w/62f20e91708c14f2b8e1330f/e/47f23a63404badcd4649270d

I would like it to say that there are no edges that it can fillet if all the edges are smooth
mb - draftsman - also FS author: View FeatureScripts
IR for AS/NZS 1100

Best Answers

  • Options
    MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    Answer ✓
    @paul_chastell

    I have redone the feature.

    annotation { "Feature Type Name" : "Fillet Everything" }
    export const filletEverything = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Fillet radius" }
            isLength(definition.filletRadius, BLEND_BOUNDS);
    
            annotation { "Name" : "Don't Fillet", "Filter" : EntityType.EDGE || EntityType.FACE }
            definition.noFillet is Query;
        }
        {
            
            //This is the edges that will be filleted
            const edgesToFillet = qSubtraction(
                    qSubtraction(
                        qBodyType(
                            qEverything(
                                EntityType.EDGE
                            ),
                            BodyType.SOLID
                        ),
                        qEntityFilter(
                            definition.noFillet,
                            EntityType.EDGE
                        )
                    ),
                    qEdgeAdjacent(
                        qEntityFilter(
                            definition.noFillet,
                            EntityType.FACE
                        ),
                        EntityType.EDGE
                    )
                );
                
            //This boolean tells the feature whether the edges are smooth or not
            var smooth is boolean = true;
    
            var edges = evaluateQuery(
                context, edgesToFillet
            );
            
            //This for loop detects whether edges are smooth
            for (var edge in edges)
            {
                //This detects whether the selected edge is smooth or not
                if (evEdgeConvexity(
                            context, {
                                "edge" : edge
                            }) != EdgeConvexityType.SMOOTH)
                {
                    smooth = false;
                    break;
                }
            }
            if (!smooth)
            {
                opFillet(
                        context, id + "fillet1",
                        {
                            "entities" : edgesToFillet,
                            "radius" : definition.filletRadius
                        }
                    );
            }
            else
            {
                throw regenError("There are no sharp edges that can be filleted.");
            }
        });
    


    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100

Answers

  • Options
    MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    @paul_chastell

    Thanks!
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Options
    MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    @paul_chastell

    Here is what I was doing: 
    opFillet(context, id + "fillet1",
                    { "entities" :
                            qSubtraction(
                                qSubtraction(
                                    qBodyType(
                                        qEverything(
                                            EntityType.EDGE
                                        ),
                                        BodyType.SOLID
                                    ),
                                    qEntityFilter(
                                        definition.noFillet,
                                        EntityType.EDGE
                                    )
                                ),
                                qEdgeAdjacent(
                                    qEntityFilter(
                                        definition.noFillet,
                                        EntityType.FACE
                                    ),
                                    EntityType.EDGE
                                )
                            ),
                        "radius" : definition.filletRadius
                    });
    definition.noFillet is the faces and edges not to fillet.


    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Options
    MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    Answer ✓
    @paul_chastell

    I have redone the feature.

    annotation { "Feature Type Name" : "Fillet Everything" }
    export const filletEverything = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Fillet radius" }
            isLength(definition.filletRadius, BLEND_BOUNDS);
    
            annotation { "Name" : "Don't Fillet", "Filter" : EntityType.EDGE || EntityType.FACE }
            definition.noFillet is Query;
        }
        {
            
            //This is the edges that will be filleted
            const edgesToFillet = qSubtraction(
                    qSubtraction(
                        qBodyType(
                            qEverything(
                                EntityType.EDGE
                            ),
                            BodyType.SOLID
                        ),
                        qEntityFilter(
                            definition.noFillet,
                            EntityType.EDGE
                        )
                    ),
                    qEdgeAdjacent(
                        qEntityFilter(
                            definition.noFillet,
                            EntityType.FACE
                        ),
                        EntityType.EDGE
                    )
                );
                
            //This boolean tells the feature whether the edges are smooth or not
            var smooth is boolean = true;
    
            var edges = evaluateQuery(
                context, edgesToFillet
            );
            
            //This for loop detects whether edges are smooth
            for (var edge in edges)
            {
                //This detects whether the selected edge is smooth or not
                if (evEdgeConvexity(
                            context, {
                                "edge" : edge
                            }) != EdgeConvexityType.SMOOTH)
                {
                    smooth = false;
                    break;
                }
            }
            if (!smooth)
            {
                opFillet(
                        context, id + "fillet1",
                        {
                            "entities" : edgesToFillet,
                            "radius" : definition.filletRadius
                        }
                    );
            }
            else
            {
                throw regenError("There are no sharp edges that can be filleted.");
            }
        });
    


    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
Sign In or Register to comment.