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.

Having issues with FeatureScrip Extrude Remove

mario_acosta380mario_acosta380 Member Posts: 6
I don't know if my previous question went by. I will ask it again. 
So, I am trying to do a custom-made feature script. The code has no errors, though instead of removing it, it is adding material. Please see my code: 
FeatureScript 2411;
// Import the FeatureScript standard library
import(path : "onshape/std/common.fs", version : "2411.0");

// Define a custom feature
annotation { "Feature Type Name" : "Custom Remove Extrude", "Editing Logic" : "FeatureScript" }
export const customRemoveExtrude = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        // Input for selecting a sketch
        annotation { "Name" : "Sketch", "Filter" : EntityType.FACE }
        definition.sketch is Query;
    }
    {
        // Define the constant extrusion depth
        // const extrusionDepth = 7 * millimeter;

        // Logic for removing the extruded material
        var extrudeDefinition = {
            "entities" : definition.sketch,
            "direction" : evOwnerSketchPlane(context, { "entity" : definition.sketch }).normal,
            "endBound" : BoundingType.THROUGH_ALL,
            "operationType" : NewBodyOperationType.REMOVE,
            // "endDepth" : extrusionDepth,
        };

        // Perform the remove extrusion operation
        opExtrude(context, id + "removeExtrude", extrudeDefinition);
    });

Answers

  • MichaelPascoeMichaelPascoe Member Posts: 1,989 PRO
    edited July 23

    There are a few different ways to do an extrude. The extrude definition you are trying to use belongs to the extrude feature not the opExtrude operation.The standard extrude feature does a lot of extra work behind the scenes that the opExtrude does not. 

    If you want to call the extrude feature and use it's functionality you can do it like this:
    Note: with the latest version of onshape/std/common.fs, you have to import the extrude feature separately.

    FeatureScript 2411;
    import(path : "onshape/std/common.fs", version : "2411.0");
    
    import(path : "12312312345abcabcabcdeff/51e8dda12148fa9d3b3888d9/aff9bec3150a48098a8184ac", version : "d95598a5a22b672285115346");
    
    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" : "Sketch", "Filter" : EntityType.FACE }
            definition.sketch is Query;
        }
        {
            var extrudeDefinition = {
                "entities" : definition.sketch,
                "direction" : evOwnerSketchPlane(context, { "entity" : definition.sketch }).normal,
                "endBound" : BoundingType.THROUGH_ALL,
                "operationType" : NewBodyOperationType.REMOVE,
            };
    
            extrude(context, id + "removeExtrude", extrudeDefinition);
        });


    Usually, when making a custom feature, you don't want all of the original features functionality. So opExtrude is recommended. Here is how you could do it with opExtrude:

    FeatureScript 2411;
    import(path : "onshape/std/common.fs", version : "2411.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" : "Sketch", "Filter" : EntityType.FACE }
            definition.sketch is Query;
        }
        {
            opExtrude(context, id + "extrude1", {
                        "entities" : definition.sketch,
                        "direction" : evOwnerSketchPlane(context, { "entity" : definition.sketch }).normal,
                        "endBound" : BoundingType.THROUGH_ALL,
                        "endDepth" : 1 * inch
                    });
    
            const extrudedPart = qCreatedBy(id + "extrude1", EntityType.BODY);
            var targets = qAllSolidBodies();
            targets = qSubtraction(targets, extrudedPart);
    
            opBoolean(context, id + "boolean1", {
                        "tools" : extrudedPart,
                        "targets" : targets,
                        "operationType" : BooleanOperationType.SUBTRACTION
                    });
        });


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • mario_acosta380mario_acosta380 Member Posts: 6
    Michael, thank you a lot. The OnShape support is amazing. Every time I ask a question it gets immediately solved. Thank you!
  • MichaelPascoeMichaelPascoe Member Posts: 1,989 PRO
    Onshape has a great community. Pretty rare to find if you look at other software. 

    I'm not sure how they do it. I think it's the combination of updates showing that they care, a legit forum platform, and the kind of people in general who use cad software are nice people. All these together make it a thriving forum.

    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.