For (var i = .. Sketch and Plane and Circular pattern

Fda
Fda Member Posts: 42 ✭✭
How could you create a with a "for (var i = ...." a Sketch in each plane.





  And how Extrude each Sketch.





jhljlñkjñl
           var sketch2 = newSketch(context, id + "sketch2", {
           "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
           });


           for (var i = 0; i < 5; i += 1)
           {
           var miPlane is string = "plane" ~ i;


           var Circle is string = "Circle" ~ i;
           
           skCircle(sketch2, miPlane, {
           "center" : vector(i, 0) * inch,
           "radius" : 1 * inch
           });

           opPlane(context, id + miPlane, {
           "plane" : plane(vector(0, 0, i) * inch, vector(0, 0, 1)),
           "width" : 6 * inch,
           "height" : 6 * inch
           });


           }

           // Create sketch entities here
           skSolve(sketch2);

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,120 image
    edited August 2019
    Making one extrude then using opPattern would be more efficient. 
    Senior Director, Technical Services, EMEA
  • MBartlett21
    MBartlett21 Member, OS Professional, Developers Posts: 2,064 ✭✭✭✭✭
  • Fda
    Fda Member Posts: 42 ✭✭
    annotation { "Feature Type Name" : "Star" }
    export const star = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "length" }
            isLength(definition.length, LENGTH_BOUNDS);
            annotation { "Name" : "radius" }
            isLength(definition.radius, LENGTH_BOUNDS);
            annotation { "Name" : "count" }
            isInteger(definition.count, POSITIVE_COUNT_BOUNDS);
    
        }
        {
           ///=======================================================================
            ///================  https://forum.onshape.com/discussion/2568/showing-whats-in-a-query
    
            var ang = 360 / definition.count * degree;
            var i;
            var j;
            var k;
    
    
            for (var cnt = 1; cnt <= definition.count; cnt += 1)
            {
                i = cos(ang * cnt);
                j = sin(ang * cnt);
                debug(context, ang * cnt / degree);
    
    
                fCylinder(context, id + "cylinder" + cnt, {
                            "bottomCenter" : vector(0, 0, 0) * meter,
                            "topCenter" : vector(i, j, 0) * definition.length,
                            "radius" : definition.radius
                        });
    
    
                debug(context, (qContainsPoint(qCreatedBy(id + "cylinder" + cnt, EntityType.FACE), vector(i, j, 50) * definition.length)));
    
    
    
            }
            ///================  https://forum.onshape.com/discussion/2568/showing-whats-in-a-query
            ///=======================================================================
    
    
            //########################################################################
            //https://forum.onshape.com/discussion/comment/38253#Comment_38253
    
            const allCuboids = qUnion([qCreatedBy(id + "cylinder", EntityType.BODY), qCreatedBy(id + "cuboidGroupB", EntityType.BODY)]);
    
            opBoolean(context, id + "boolean1", {
                        "tools" : allCuboids,
                        "operationType" : BooleanOperationType.UNION
                    });
    
    
            opTransform(context, id + "transform2", {
                        "bodies" : allCuboids,
                        "transform" : transform(vector(1, 2, 50) * millimeter)
                    });
    
    
            //https://forum.onshape.com/discussion/comment/38253#Comment_38253
           //########################################################################
    
        }, { /* default parameters */ });
    Sorry for a delay in answering. This is wanted
  • Fda
    Fda Member Posts: 42 ✭✭
    annotation { "Feature Type Name" : "opPattern" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
        }
        {
            // Define the function's action
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });
    
            skCircle(sketch1, "circle1", {
                        "center" : vector(0, 0) * millimeter,
                        "radius" : 1 * millimeter
                    });
    
            skSolve(sketch1);
    
    
            extrude(context, id + "extrude1", {
                        "entities" : qSketchRegion(id + "sketch1"),
                        "endBound" : BoundingType.BLIND,
                        "depth" : -100 * millimeter
                    });
    
    
    ///========= AXIS
            var sketch2 = newSketch(context, id + "sketch2", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });
    
            skCircle(sketch2, "circle2", {
                        "center" : vector(0, 0) * millimeter,
                        "radius" : 1 * millimeter
                    });
    
            skSolve(sketch2);
    
    ///========= AXIS
    
           var miBox = qCreatedBy(id + "extrude1", EntityType.BODY);
    
            opPattern(context, id + "pattern1", {
                        "entities" : entities, //??????
                        "transforms" : transforms,//??????
                        "instanceNames" : instanceNames//??????
                    });
    
        });
    NeilCooke said:
    Making one extrude then using opPattern would be more efficient. 
    Please could you give a complete example with a code, perhaps more users will help you with the operation of "opPattern".
  • Jake_Rosenfeld
    Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646 image
    @fermin_fermin_1

    opPattern documentation:
    https://cad.onshape.com/FsDoc/library.html#opPattern-Context-Id-map

    Just typing this up directly on the forum, so there may be some slight typos, but the general idea is:

    const lineToRotateAround = line(WORLD_ORIGIN, Z_DIRECTION);
    const angleIncrement = (360 * degree) / definition.count;
    
    var transforms = [];
    var instanceNames = [];
    for (var i = 1; i < definition.count; i += 1) // Iterate from 1 -> (definition.count - 1) because we have already created the base (0) instance
    {
        const currAngle = i * angleIncrement;
        const currTransform = rotationAround(lineToRotateAround, i * angleIncrement);
        // Append the currTransform to the transforms list
        transforms = append(transforms, currTransform);
        // instance names don't matter, they just need to be unique strings
        instanceNames = append(instanceNames, toString(i));
    }
    
    const patternId = id + "pattern";
    opPattern(context, patternId, {
        "entities" : qCreatedBy(originExtrudeId, EntityType.BODY),
        "transforms" : transforms,
        "instanceNames" : instanceNames
    });
    
    const booleanId = id + "boolean"; 
    opBoolean(context, booleanId, {
        "tools" : qUnion([qCreatedBy(originalExtrudeId, EntityType.BODY), qCreatedBy(patternId, EntityType.BODY)]),
        "operationType" : BooleanOperationType.UNION
    });

    Hope this helps.  Feel free to comment back with questions.
    Jake Rosenfeld - Modeling Team
  • Fda
    Fda Member Posts: 42 ✭✭
    @fermin_fermin_1

    opPattern documentation:
    https://cad.onshape.com/FsDoc/library.html#opPattern-Context-Id-map

    Just typing this up directly on the forum, so there may be some slight typos, but the general idea is:

    const lineToRotateAround = line(WORLD_ORIGIN, Z_DIRECTION);
    const angleIncrement = (360 * degree) / definition.count;
    
    var transforms = [];
    var instanceNames = [];
    for (var i = 1; i < definition.count; i += 1) // Iterate from 1 -> (definition.count - 1) because we have already created the base (0) instance
    {
        const currAngle = i * angleIncrement;
        const currTransform = rotationAround(lineToRotateAround, i * angleIncrement);
        // Append the currTransform to the transforms list
        transforms = append(transforms, currTransform);
        // instance names don't matter, they just need to be unique strings
        instanceNames = append(instanceNames, toString(i));
    }
    
    const patternId = id + "pattern";
    opPattern(context, patternId, {
        "entities" : qCreatedBy(originExtrudeId, EntityType.BODY),
        "transforms" : transforms,
        "instanceNames" : instanceNames
    });
    
    const booleanId = id + "boolean"; 
    opBoolean(context, booleanId, {
        "tools" : qUnion([qCreatedBy(originalExtrudeId, EntityType.BODY), qCreatedBy(patternId, EntityType.BODY)]),
        "operationType" : BooleanOperationType.UNION
    });

    Hope this helps.  Feel free to comment back with questions.




    
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });
    
            skCircle(sketch1, "circle1", {
                        "center" : vector(0, 0) * millimeter,
                        "radius" : 1 * millimeter
                    });
    
            skSolve(sketch1);
    
    
            extrude(context, id + "extrude1", {
                        "entities" : qSketchRegion(id + "sketch1"),
                        "endBound" : BoundingType.BLIND,
                        "depth" : -100 * millimeter
                    });
    
    
    
            var originExtrudeId = qCreatedBy(id + "extrude1", EntityType.FACE);// originExtrudeId ???????
    
    
            var MyCount = 5;
            const lineToRotateAround = line(WORLD_ORIGIN, Z_DIRECTION);
            const angleIncrement = (360 * degree) / MyCount;
    
            var transforms = [];
            var instanceNames = [];
                    
    
            //definition.count -> MyCount
            for (var i = 1; i < MyCount; i += 1) // Iterar de 1 -> (definition.count - 1) porque ya hemos creado la instancia base (0)
            {
                const currAngle = i * angleIncrement;
                const currTransform = rotationAround(lineToRotateAround, i * angleIncrement);
                // Añadir currTransform a la lista de transformaciones
                transforms = append(transforms, currTransform);
                // los nombres de instancia no importan, solo deben ser cadenas únicas
                instanceNames = append(instanceNames, toString(i));
            }
    
    
    
            const patternId = id + "pattern";
            opPattern(context, patternId, {
                        "entities" : qCreatedBy(originExtrudeId, EntityType.BODY),
                        "transforms" : transforms,
                        "instanceNames" : instanceNames
                    });
    
    
            const booleanId = id + "boolean";
            opBoolean(context, booleanId, {
                        "tools" : qUnion([qCreatedBy(originalExtrudeId, //variable originalExtrudeId not found 
                        EntityType.BODY), qCreatedBy(patternId, EntityType.BODY)]),
                        "operationType" : BooleanOperationType.UNION
                    });
    
    
        });
    it's wrong?  :'(
  • MBartlett21
    MBartlett21 Member, OS Professional, Developers Posts: 2,064 ✭✭✭✭✭
    @fermin_fermin_1
    You should use var <b>originExtrudeId</b> = id + "extrude1";
    where you had var originExtrudeId = qCreatedBy(id + "extrude1", EntityType.FACE);// originExtrudeId ???????

    and leave the rest of the code the same.
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Jake_Rosenfeld
    Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646 image
    @fermin_fermin_1

    The reason it is saying "variable originalExtrudeId not found" is because you are trying to use the variable "originalExtrudeId", and earlier you declared it as "var originExtrudeId = ...".  These two names aren't the same.

    Otherwise, @MBartlett21 is correct:
    const originalExtrudeId = id + "extrude";
    opExtrude(context, originalExtrudeId, {
        ...
    });
    
    ...
    
    const patternId = id + "pattern";
    opPattern(context, patternId, {
        "entities" : qCreatedBy(originalExtrudeId, EntityType.BODY)
    });


    Jake Rosenfeld - Modeling Team
  • MBartlett21
    MBartlett21 Member, OS Professional, Developers Posts: 2,064 ✭✭✭✭✭
    These two names aren't the same.
    @Jake_Rosenfeld
    That is exactly what I didn't notice.
    I thought that his feature was failing because it would have been qCreatedBy(qCreatedBy(id + "extrude", EntityType.FACE), EntityType.BODY)
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Fda
    Fda Member Posts: 42 ✭✭
    @fermin_fermin_1
    You should use var <b>originExtrudeId</b> = id + "extrude1";
    where you had var originExtrudeId = qCreatedBy(id + "extrude1", EntityType.FACE);// originExtrudeId ???????

    and leave the rest of the code the same.
    Thank you very much MBartlett21

    annotation { "Feature Type Name" : "My opPattern" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
        }
        {
            // Define the function's action
    
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });
    
            skCircle(sketch1, "circle1", {
                        "center" : vector(0, 0) * millimeter,
                        "radius" : 1 * millimeter
                    });
    
            skSolve(sketch1);
    
    
            extrude(context, id + "extrude1", {
                        "entities" : qSketchRegion(id + "sketch1"),
                        "endBound" : BoundingType.BLIND,
                        "depth" : -100 * millimeter
                    });
    
    
            var originExtrudeId = id + "extrude1";
            var MyCount = 5;
            const lineToRotateAround = line(WORLD_ORIGIN, Z_DIRECTION);
            const angleIncrement = (360 * degree) / MyCount;
    
            var transforms = [];
            var instanceNames = [];
    
    
            //definition.count -> MyCount
            for (var i = 1; i < MyCount; i += 1) // Iterate from 1 -> (definition.count - 1) because we have already created the base (0) instance
            {
                const currAngle = i * angleIncrement;
                const currTransform = rotationAround(lineToRotateAround, i * angleIncrement);
                // Append the currTransform to the transforms list
                transforms = append(transforms, currTransform);
                // instance names don't matter, they just need to be unique strings
                instanceNames = append(instanceNames, toString(i));
            }
    
    
    
            var patternId = id + "pattern";
    
            opPattern(context, patternId, {
                        "entities" : qCreatedBy(originExtrudeId, EntityType.BODY),
                        "transforms" : transforms,
                        "instanceNames" : instanceNames
                    });
    
    
           //// boolean part
            const My_opPattern = qUnion([qCreatedBy(id + "pattern", EntityType.BODY), qCreatedBy(id + "extrude1", EntityType.BODY)]);
    
            const booleanId = id + "boolean";
            opBoolean(context, booleanId, {
                        "tools" : My_opPattern,
                        "operationType" : BooleanOperationType.UNION
                    });
    
        });