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 Set Sketch Origin to Plane Origin in Onshape?

he_qiu143he_qiu143 Member Posts: 7 EDU

I have some CAD feature models that include planar sketches defined by 3D points and coordinate systems, as well as extrusions. Now, I need to recreate the same models in Onshape based on this data.

The main issue arises during the sketching process. Since Onshape's GUI does not allow defining a sketch plane's origin using 3D points, I have to use the API to create sketches. My current approach involves creating a FeatureScript (FeatureStudio) feature that generates a plane based on given parameters (origin, normal, and x-axis). Then, I draw the sketch on this plane.

FeatureScript 2581;
import(path : "onshape/std/common.fs", version : "2581.0");

annotation { "Feature Type Name" : "Add a plane", "Feature Type Description" : "" }
export const addPlane = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {

        definition.OriginX is string;
        definition.OriginY is string;
        definition.OriginZ is string;

        definition.NormalX is string;
        definition.NormalY is string;
        definition.NormalZ is string;

        definition.XX is string;
        definition.XY is string;
        definition.XZ is string;

    }
    {
        opPlane(context, id + "plane", {
                    "plane" : plane(vector(stringToNumber(definition.OriginX), stringToNumber(definition.OriginY), stringToNumber(definition.OriginZ)) * meter,
                    vector(stringToNumber(definition.NormalX), stringToNumber(definition.NormalY), stringToNumber(definition.NormalZ)),
                    vector(stringToNumber(definition.XX), stringToNumber(definition.XY), stringToNumber(definition.XZ)))
                });
        var plane = qCreatedBy(makeId("Front"), EntityType.FACE);
        println(plane);
        var plane2 = qCreatedBy(id, EntityType.EDGE);
        print(plane2);

    });


However, I found that the sketch's origin does not match the plane's origin; instead, it aligns with the world coordinate system's origin.(The part circled in red in the image is the plane where the sketch is located.)

I know that in FeatureScript, when using newSketchPlane, the specified origin becomes the sketch's origin. However, sketches created this way cannot be further edited in the GUI and require many parameters to be passed in.

So, my question is: In my initial approach, how can I ensure that the sketch's origin is set to the plane's origin?

Does anyone know how to handle this?

Best Answer

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,792
    Answer ✓

    Use a Mate connector for the Sketch plane then you can control the origin and orientation without FS.

    Senior Director, Technical Services, EMEA

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,792
    Answer ✓

    Use a Mate connector for the Sketch plane then you can control the origin and orientation without FS.

    Senior Director, Technical Services, EMEA
Sign In or Register to comment.