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

worldToPlane() gives inconsistent location?

alan_1alan_1 Member Posts: 14 EDU
I am trying to get a 2D point on a surface that I can then extrude.  In this example, I am using a line's endpoint and attempting to extrude a circle with that point as its center.  it works in one orientation, but when I switch orientations it either moves the extrude or fails completely (extrude error).  In my testing, the line is drawn on a flat surface and is well within the interior of that surface.  The surface is of a simple XYZ rectangular block.  Think rectangle in "top" plane then extrude.  So we're not talking non-90-degree angles at the moment.
Here's the code snippet.
I figure I'm misusing something, but not quite sure what the misuse is.

            var endpoints = evaluateQuery(context, qVertexAdjacent(line, EntityType.VERTEX));
            var A is Vector = evVertexPoint(context, { "vertex" : endpoints[0] });
            var aInPlane = worldToPlane(sketchPlane, A);
            var Avec = vector(aInPlane[0], aInPlane[1]);
            var circleB = skCircle(sketch1, "circleA" ~ index, {
                "center" : Avec,
                "radius" : definition.width / 2
            });
            skSolve(sketch1);
            var exid = id + ("extrude1" ~ index);
            extrude(context, exid, {
                    "entities" : qSketchRegion(sketchid),
                    "endBound" : BoundingType.UP_TO_BODY,
                    "depth" : (definition.height + 1 * meter),
                    "endBoundEntityBody" : definition.targetBody,
                    "operationType" : NewBodyOperationType.ADD,
                    "defaultScope" : false,
                    "booleanScope" : definition.targetBody,
                    "oppositeDirection" : true
            });

Comments

  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,177
    I am going to guess you're using newSketch to create the sketch (that part of your code is actually missing) -- that gives you pretty poor control over the sketch orientation and origin.  For FS, I recommend using newSketchOnPlane instead and passing in the plane.  See https://cad.onshape.com/FsDoc/library.html#module-sketch.fs
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    alan_1alan_1 Member Posts: 14 EDU
    I have been using a method from the FeatureScript Snap Hook example.  It looks similar to this:
                var sketchPlane = evOwnerSketchPlane(context, { "entity" : endpoints[0] });
                var topPlane = plane(sketchPlane.origin +  (definition.height) * sketchPlane.normal, sketchPlane.normal);
                var sketchid = id + ("sketch1" ~ index);
                var sketch1 = newSketchOnPlane(context, sketchid, { "sketchPlane" : topPlane });

    I suspect that somewhere in this code snippet the orientation gets flipped.  Perhaps the use of plane().  I tried using sketchPlane instead of topPlane and have solved my issue.

  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,177
    Ah I think I see -- you're specifying topPlane by a point and normal, so the reference (x axis in the plane) is getting automatically set instead of being set from sketchPlane.  Pass sketchPlane.x as the third argument to plane and that should solve your problem.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.