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.

FeatureScript for removing threads from imported parts?

dean_brettledean_brettle Member Posts: 10 EDU
Is there an existing FS that can be used to remove threads from imported parts like bolts/screws and nuts to improve performance? Or has someone attempted this in the past and not succeeded?


Comments

  • Jake_DelanoJake_Delano Member, Onshape Employees Posts: 41
    Use Delete Face on the threads with the Heal option selected
  • EvanReeseEvanReese Member, Mentor Posts: 2,082 ✭✭✭✭✭
    I started to write one and got it working in one click for a standard machine screw from McMaster, but there are so many edge cases that it didn't make sense to keep trying when the workflow using native features is pretty easy, as Jake describes.
    Here's a comparison of the custom feature vs delete face. I've abandoned development of the feature in favor of just using delete face.


    Evan Reese
  • dean_brettledean_brettle Member Posts: 10 EDU
    edited February 2022
    Thanks @Evan_Reese and @Jake_Delano, but I think a thread removal FS might still be useful when dealing with a PS that has many screws. It would be very convenient to be able to tell it to remove threads from all of the parts. @Evan_Reese, would you be willing to make your Thread Remover FS public so it can be used as a starting point?

    P.S. Sorry for the late reply. The notification email went to Spam...
  • EvanReeseEvanReese Member, Mentor Posts: 2,082 ✭✭✭✭✭
    @dean_brettle

    Here's the code, but the challenge is designing good query strategies that will always find the correct faces to delete and nothing extra. The method i'm using here really only works for this one kind of screw, but would fail with an internal thread, tri-lobed thread-forming screw, wood screw, and probably many other situations where you'd want it to work. I could imagine the feature would become quite long to cover all of these cases, and would likely still be buggy-feeling.

    FeatureScript 1364;
    import(path : "onshape/std/geometry.fs", version : "1364.0");

    annotation { "Feature Type Name" : "Thread remover" }
    export const threadRemover = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Screw threads", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
            definition.screw is Query;
        }
        {
            var faces = evaluateQuery(context, qConvexConnectedFaces(definition.screw));
            var helicalFaces = [];
            var cylindricalFaces = [];
            for (var i = 0; i < size(faces); i += 1)
            {
                var face = faces[i];
                var faceType = evSurfaceDefinition(context, {
                        "face" : face
                    });
                if (canBePlane(faceType) || canBeCone(faceType))
                {
                    continue;
                }
                if (canBeCylinder(faceType))
                {
                    cylindricalFaces = append(cylindricalFaces, face);
                }
                if (faceType.surfaceType == SurfaceType.OTHER)
                {
                    helicalFaces = append(helicalFaces, face);
                }
            }
            
                var smallCyl;
            try silent
            {
                var cyl1 = evSurfaceDefinition(context, {
                            "face" : cylindricalFaces[0]
                        }).radius;
                var cyl2 = evSurfaceDefinition(context, {
                            "face" : cylindricalFaces[1]
                        }).radius;

                if (cyl1 < cyl2)
                {
                    smallCyl = cylindricalFaces[0];
                }
                else
                {
                    smallCyl = cylindricalFaces[1];
                }

            }
            catch (error)
            {
                smallCyl = cylindricalFaces[0];
            }

            var deleteFaces = qUnion([smallCyl, qUnion(helicalFaces)]);
            debug(context, deleteFaces, DebugColor.RED);
            opDeleteFace(context, id + "deleteFace1", {
                        "deleteFaces" : deleteFaces,
                        "includeFillet" : false,
                        "capVoid" : false,
                        "leaveOpen" : false
                    });

        });

    Evan Reese
Sign In or Register to comment.