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.

Can't Sketch on Plane Created with opPlane

matthew_mueller295matthew_mueller295 Member Posts: 6 PRO
Hello,

I am trying to create a new plane using opPlane, then create new sketch features on it. The plane shows up, but not the sketch. The body of the FS code is below. Thanks!

        var plane1 = opPlane(context, id + "plane1", {
                "plane" : plane(vector(0, 0, 2) * inch, vector(0, 0, 1), vector(1, 0, 0)),
                "width" : 6 * inch,
                "height" : 6 * inch
        });
        
        var sketch1 = newSketch(context, id + "sketch1", {
                "sketchPlane" : qCreatedBy(makeId("plane1"), EntityType.FACE)
        });
        // Create sketch entities here
        skText(sketch1, "text1", {
                "text" : "Hello",
                "fontName" : "OpenSans-Regular.ttf",
                "firstCorner" : vector(0, 0) * inch,
                "secondCorner" : vector(1, 1) * inch
        });
        skSolve(sketch1);

Comments

  • _anton_anton Member, Onshape Employees Posts: 10
    edited March 25
    Morning! The issue is where you're placing the sketch:

    "sketchPlane" : qCreatedBy(makeId("plane1"), EntityType.FACE)

    Try replacing the

    makeId("plane1")

    with

    id + "plane1"
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,578
    I like to store this in a variable so that I don't have to rely on typing the same string correctly over and over:
    const planeId = id + "plane";
    opPlane(context, planeId, {...});
    
    const sketchId = id + "sketch";
    var sketch = newSketch(context, sketchId, { "sketchPlane" : qCreatedby(planeId, EntityType.FACE) });
    

    Additionally, it might be useful to know that if you do not need this plane to actually show up in your part studio, or if you are just going to delete it later, you could use newSketchOnPlane directly instead of newSketch.  
    https://cad.onshape.com/FsDoc/library.html#newSketchOnPlane-Context-Id-map

    Then your code would just look like:
    const sketchId = id + "sketch";
    var sketch = newSketchOnPlane(context, sketchId, { "sketchPlane" : plane(vector(0, 0, 2) * inch, vector(0, 0, 1), vector(1, 0, 0)) });

    Jake Rosenfeld - Modeling Team
  • matthew_mueller295matthew_mueller295 Member Posts: 6 PRO
    Changing it to id + "plane1" worked. And good to know about the newSketchOnPlane function. Thank you both!
Sign In or Register to comment.