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.

Creating acircular pattern in featureScript

wayne_jayeswayne_jayes Member Posts: 13 ✭✭
Would someone be kind enough to look at the script in this document
https://cad.onshape.com/documents/623b04759dbfa9159178fe48/w/3f75f7adc024168001e48971/e/ebff95d2dd43547b3b99a055
and point me in the right direction to fix the circularPattern.  I am trying to make a flange for joining sections of pipe

Best Answers

  • mickaelmickael Member Posts: 8 ✭✭
    edited June 2016 Answer ✓
    There is just a mistake in the transform vector (180 instead of 360 degrees)   :wink:


    annotation { "Feature Type Name" : "Flange" }
    export const myFlange = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "Outside Diameter" }
            isLength(definition.OD, LENGTH_BOUNDS);
            annotation { "Name" : "PCD" }
            isLength(definition.PCD, LENGTH_BOUNDS);
            annotation { "Name" : "Internal Diameter" }
            isLength(definition.ID, LENGTH_BOUNDS);
            annotation { "Name" : "Hole Diameter" }
            isLength(definition.HoleDia, LENGTH_BOUNDS);
            annotation { "Name" : "Flange Thickness" }
            isLength(definition.THK, LENGTH_BOUNDS);
            annotation { "Name" : "No of Holes" }
            isInteger(definition.NumHoles, POSITIVE_COUNT_BOUNDS);
        }
        {
    
            fCylinder(context, id + "cylinder1", {
                        "bottomCenter" : vector(0, 0, 0) * millimeter,
                        "topCenter" : vector(0, 0, 1) * definition.THK,
                        "radius" : 0.5 * definition.OD
                    });
            fCylinder(context, id + "cylinder2", {
                        "bottomCenter" : vector(0, 0, 0) * millimeter,
                        "topCenter" : vector(0, 0, 1) * definition.THK,
                        "radius" : 0.5 * definition.ID
                    });
    
            booleanBodies(context, id + "boolean1", {
                        "tools" : qCreatedBy(id + "cylinder2", EntityType.BODY),
                        "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY),
                        "operationType" : BooleanOperationType.SUBTRACTION
                    });
    
            for (var i = 0; i < definition.NumHoles; i += 1)
            {
                fCylinder(context, id + i + "cylinder3", {
                            "bottomCenter" : vector(0, 0, 0) * millimeter,
                            "topCenter" : vector(0, 0, 1) * definition.THK,
                            "radius" : 0.5 * definition.HoleDia
                        });
    
                opTransform(context, id + i + "transform1", {
                            "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY),
                            "transform" : transform(vector(cos(i * 360 * degree / definition.NumHoles), sin(i * 360 * degree / definition.NumHoles), 0) * definition.PCD / 2)
                        });
    
                booleanBodies(context, id + i + "boolean2", {
                            "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY),
                            "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY),
                            "operationType" : BooleanOperationType.SUBTRACTION
                        });
            }
        });

    And it works :smiley:

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    Looks like you capitalized a couple of the parameters: "Angle" should be "angle" and "InstanceCount" should be "instanceCount".  The query for "axis" also needs a cylindrical face, rather than the cylinder body.  There may be other issues I can't see, but that's my first glance.

    For what you are trying to do, a circular pattern is one possibility, but it might be easier to just put your cylinder, transform, and boolean into a for loop.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • wayne_jayeswayne_jayes Member Posts: 13 ✭✭
    Hi Ilya, thanks for the pointers, unfortunately I still need some further help, I implemented your suggestions regarding "angle", "instanceCount", and the cylindrical face, but the problem was not solved.  I tried the for loop, but again my knowledge of the onshape coding is not up to the task. I'm battling to find the right help in the language reference for FeatureScript. I am a compentant php coder, perhaps there are some example FeatureScript code fragments I could use as an example to learn from. Thanks
  • mickaelmickael Member Posts: 8 ✭✭
    edited June 2016 Answer ✓
    There is just a mistake in the transform vector (180 instead of 360 degrees)   :wink:


    annotation { "Feature Type Name" : "Flange" }
    export const myFlange = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "Outside Diameter" }
            isLength(definition.OD, LENGTH_BOUNDS);
            annotation { "Name" : "PCD" }
            isLength(definition.PCD, LENGTH_BOUNDS);
            annotation { "Name" : "Internal Diameter" }
            isLength(definition.ID, LENGTH_BOUNDS);
            annotation { "Name" : "Hole Diameter" }
            isLength(definition.HoleDia, LENGTH_BOUNDS);
            annotation { "Name" : "Flange Thickness" }
            isLength(definition.THK, LENGTH_BOUNDS);
            annotation { "Name" : "No of Holes" }
            isInteger(definition.NumHoles, POSITIVE_COUNT_BOUNDS);
        }
        {
    
            fCylinder(context, id + "cylinder1", {
                        "bottomCenter" : vector(0, 0, 0) * millimeter,
                        "topCenter" : vector(0, 0, 1) * definition.THK,
                        "radius" : 0.5 * definition.OD
                    });
            fCylinder(context, id + "cylinder2", {
                        "bottomCenter" : vector(0, 0, 0) * millimeter,
                        "topCenter" : vector(0, 0, 1) * definition.THK,
                        "radius" : 0.5 * definition.ID
                    });
    
            booleanBodies(context, id + "boolean1", {
                        "tools" : qCreatedBy(id + "cylinder2", EntityType.BODY),
                        "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY),
                        "operationType" : BooleanOperationType.SUBTRACTION
                    });
    
            for (var i = 0; i < definition.NumHoles; i += 1)
            {
                fCylinder(context, id + i + "cylinder3", {
                            "bottomCenter" : vector(0, 0, 0) * millimeter,
                            "topCenter" : vector(0, 0, 1) * definition.THK,
                            "radius" : 0.5 * definition.HoleDia
                        });
    
                opTransform(context, id + i + "transform1", {
                            "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY),
                            "transform" : transform(vector(cos(i * 360 * degree / definition.NumHoles), sin(i * 360 * degree / definition.NumHoles), 0) * definition.PCD / 2)
                        });
    
                booleanBodies(context, id + i + "boolean2", {
                            "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY),
                            "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY),
                            "operationType" : BooleanOperationType.SUBTRACTION
                        });
            }
        });

    And it works :smiley:

  • wayne_jayeswayne_jayes Member Posts: 13 ✭✭
    Thank you for your help.  just what I needed to get me going.
Sign In or Register to comment.