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.

Options

How to make a duplicate of a part in featurescript

leti_ryderleti_ryder Member Posts: 7 EDU
Hi guys!
I am trying to make a duplicate of a part in featurescript, I am using opPattern which requires a transform input. I am not sure what to enter.


   var bfsBody = qCreatedBy(sketchId + "revolve1", EntityType.BODY);
        var bfsBody = qCreatedBy(sketchId + "revolve1");
        debug(context, bfsBody);
        
        opPattern(context, id + "pattern1", {
                "entities" : bfsBody,
                "transforms" :  transform(vector(1, 2, 50) * millimeter),
                "instanceNames" :  "scaled_body"
        });
    

Answers

  • Options
    mahirmahir Member, Developers Posts: 1,291 ✭✭✭✭✭
    I believe the input for "transforms" is an array of transforms. So you'll need to add brackets [] around the transform command to turn it into an array of one transform. The transform dictates where exactly the copy is going to be placed. In your example, you're using a transform with a single distance vector input of (1, 2, 50) * millimeter. That means your copy will be moved 1/2/50mm in x/y/z. Check out the documentation at the link below for details on more complicated transforms involving scaling/rotation along with specific syntax.

    https://cad.onshape.com/FsDoc/library.html#module-transform.fs
  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,717 PRO
    edited December 2022

    Echoing @mahir. opPattern needs a "transform" of some sort to know what to do with the new item.
    The transform and the name must be in an array [ ]. You can transform the new patterned entity to its original position like this:
        var bfsBody = qCreatedBy(sketchId + "revolve1", EntityType.BODY);
        var bfsBody = qCreatedBy(sketchId + "revolve1");
        debug(context, bfsBody);
    
        opPattern(context, id + "pattern1", {
                    "entities" : bfsBody,
                    "transforms" : [transform(XY_PLANE, XY_PLANE)],
                    "instanceNames" : ["scaled_body"]
                });

    If you wanted to pattern multiple items the transforms and the names must be separated by a comma:
        var bfsBody = qCreatedBy(sketchId + "revolve1", EntityType.BODY);
        var bfsBody = qCreatedBy(sketchId + "revolve1");
        debug(context, bfsBody);
    
        opPattern(context, id + "pattern1", {
                    "entities" : bfsBody,
                    "transforms" : [transform(XY_PLANE, XY_PLANE), transform(XY_PLANE, XY_PLANE), transform(XY_PLANE, XY_PLANE)],
                    "instanceNames" : ["scaled_body1", "scaled_body2", "scaled_body3"]
                });


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 PRO
    Michael is right on the money here. If you don't want to move it in any way you can use identityTransform() to make a transform that doesn't do anything instead of transform(XY_PLANE, XY_PLANE)
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.