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 mirror a feature?


I would like to mirror the opSweep and opBoolean function, on the opposite side of a cylinder.
The documentation says, that i need a featureList as an input for the instanceFunction. Could not find out, how i can construct it.

Or is there another way I could achieve this??
        opSweep(context, id + "sweep1", {
                "profiles" : qSketchRegion(id + "sketch1"),
                "path" :  qUnion([qNthElement(edges1, 0), qNthElement(edges2, 0), qNthElement(edges3, 0), qNthElement(edges4, 0)])
        });        
                   
        opBoolean(context, id + "boolean3", {
                "tools" : qCreatedBy(id + "sweep1", EntityType.BODY),
                "targets" : qCreatedBy(id + "extrude1", EntityType.BODY),
                "operationType" : BooleanOperationType.SUBTRACTION,
                "keepTools" : false
        });  
        
        opPlane(context, id + "plane1", {
                "plane" : plane(vector(0, 0, eLength-(definition.lPiston/2)) * millimeter, vector(0, 0, eLength-(definition.lPiston/2))*millimeter)
        });
                
        mirror(context, id + "mirror3", { 
        "patternType" : MirrorType.FEATURE,
        "instanceFunction" : {},
        "mirrorPlane" : qCreatedBy(id + "plane1", EntityType.FACE)
        });<br>

Best Answer

  • MichaelPascoeMichaelPascoe Member Posts: 1,988 PRO
    edited August 2022 Answer ✓
    Hi @sebastian_rigger837, you could try something similar to this:   Sweep  >  Mirror  >  Boolean

    Comments have been placed in the code for easier understanding of what each component does.
    When using featurescript, you can use the opPattern operation to copy parts in various ways of transform. 
    FeatureScript 1821;
    import(path : "onshape/std/geometry.fs", version : "1821.0");
    
    annotation { "Feature Type Name" : "Sweep Mirror" }
    export const sweepMirror = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Profile to sweep", "Filter" : EntityType.FACE }
            definition.profile is Query;
    
            annotation { "Name" : "Sweep path", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.path is Query;
    
            annotation { "Name" : "Mirror mate", "Filter" : BodyType.MATE_CONNECTOR || BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
            definition.mirrorMate is Query;
    
            annotation { "Name" : "Targets", "Filter" : EntityType.BODY }
            definition.targets is Query;
    
        }
        {
            // Sweep profile along path
            opSweep(context, id + "sweep1", {
                        "profiles" : definition.profile,
                        "path" : definition.path
                    });
    
            // Get the swept part
            const sweptPart = qCreatedBy(id + "sweep1", EntityType.BODY);
    
            // Turn the mate connector into a coord system
            const mirrorCsys = evMateConnector(context, {
                        "mateConnector" : definition.mirrorMate
                    });
    
            // Create a construction plane to mirror accross
            const mirrorPlane = plane(mirrorCsys);
    
            // Pattern is used to copy and mirror things
            opPattern(context, id + "pattern1", {
                        "entities" : sweptPart,
                        "transforms" : [mirrorAcross(mirrorPlane)], // Transform is placed inside an array []
                        "instanceNames" : ["Copy"] // Names are placed inside an array []
                    });
    
            // Get the mirrored parts
            const mirroredParts = qCreatedBy(id + "pattern1", EntityType.BODY);
    
            // Debug the parts green
            debug(context, qUnion([sweptPart, mirroredParts]), DebugColor.GREEN);
    
            // Boolean subtract the parts from the target
            opBoolean(context, id + "boolean1", {
                        "tools" : qUnion([sweptPart, mirroredParts]),
                        "targets" : definition.targets,
                        "operationType" : BooleanOperationType.SUBTRACTION
                    });
        });
    https://cad.onshape.com/documents/343178350105cea556ab3d23/w/990bfe172e0ed3c440868636/e/a7b94e644da0af9ed6cb77ad




    Learn more about the Gospel of Christ  ( Here )

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

Answers

  • MichaelPascoeMichaelPascoe Member Posts: 1,988 PRO
    edited August 2022 Answer ✓
    Hi @sebastian_rigger837, you could try something similar to this:   Sweep  >  Mirror  >  Boolean

    Comments have been placed in the code for easier understanding of what each component does.
    When using featurescript, you can use the opPattern operation to copy parts in various ways of transform. 
    FeatureScript 1821;
    import(path : "onshape/std/geometry.fs", version : "1821.0");
    
    annotation { "Feature Type Name" : "Sweep Mirror" }
    export const sweepMirror = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Profile to sweep", "Filter" : EntityType.FACE }
            definition.profile is Query;
    
            annotation { "Name" : "Sweep path", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.path is Query;
    
            annotation { "Name" : "Mirror mate", "Filter" : BodyType.MATE_CONNECTOR || BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
            definition.mirrorMate is Query;
    
            annotation { "Name" : "Targets", "Filter" : EntityType.BODY }
            definition.targets is Query;
    
        }
        {
            // Sweep profile along path
            opSweep(context, id + "sweep1", {
                        "profiles" : definition.profile,
                        "path" : definition.path
                    });
    
            // Get the swept part
            const sweptPart = qCreatedBy(id + "sweep1", EntityType.BODY);
    
            // Turn the mate connector into a coord system
            const mirrorCsys = evMateConnector(context, {
                        "mateConnector" : definition.mirrorMate
                    });
    
            // Create a construction plane to mirror accross
            const mirrorPlane = plane(mirrorCsys);
    
            // Pattern is used to copy and mirror things
            opPattern(context, id + "pattern1", {
                        "entities" : sweptPart,
                        "transforms" : [mirrorAcross(mirrorPlane)], // Transform is placed inside an array []
                        "instanceNames" : ["Copy"] // Names are placed inside an array []
                    });
    
            // Get the mirrored parts
            const mirroredParts = qCreatedBy(id + "pattern1", EntityType.BODY);
    
            // Debug the parts green
            debug(context, qUnion([sweptPart, mirroredParts]), DebugColor.GREEN);
    
            // Boolean subtract the parts from the target
            opBoolean(context, id + "boolean1", {
                        "tools" : qUnion([sweptPart, mirroredParts]),
                        "targets" : definition.targets,
                        "operationType" : BooleanOperationType.SUBTRACTION
                    });
        });
    https://cad.onshape.com/documents/343178350105cea556ab3d23/w/990bfe172e0ed3c440868636/e/a7b94e644da0af9ed6cb77ad




    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.