Simple Polyline Sketch Example on Selected Plane

thomas_allsup
thomas_allsup Member, User Group Leader Posts: 4 ✭
I can't find a Featurescript example where the user picks the plane or face in the precondition area.  All the examples I find use the "TOP" but I want to select one of the datums or an existing face to create my canned polyline logo.  Help!

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    You just need to query a planar face, like this:
            annotation { "Name" : "Plane", "Filter" : EntityType.FACE && GeometryType.PLANE, "MaxNumberOfPicks" : 1 }
            definition.plane is Query;

    Senior Director, Technical Services, EMEA
  • thomas_allsup
    thomas_allsup Member, User Group Leader Posts: 4 ✭
    Yes - I got that part working.  I can select the various planes and faces of a cube.  My problem is the execution part, I put:

            var face = definition.face;  //in your example, this would have been "plane"
                   
            var sketch1 = newSketchOnPlane(context, id + "sketch1", {"sketchPlane" : face});   // if I change this "TOP" like all the examples, it will draw on the top plane 
                                    
            skPolyline(sketch1, "polyline1", {"points" : [vector( 0,  0) * inch, vector( 1, 1) * inch, vector( 2,0) * inch, vector( 0,  0) * inch]}); // drawing a simple triangle  - this is where I would put my logo or other shape
            
            skSolve(sketch1);
            
            opExtrude(context, id + "extrude", {"entities" : qSketchRegion(id+"sketch1") , "endBound" : BoundingType.BLIND,"endDepth" : 1 * inch });


    Thanks for the insights (I love the videos by the way and I have watched almost all of them).
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
            var face = evPlane(context, { "face" : definition.face }); // definition.face is a Query, not a plane
    
            var sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : face });
    
            skPolyline(sketch1, "polyline1", { "points" : [vector(0, 0) * inch, vector(1, 1) * inch, vector(2, 0) * inch, vector(0, 0) * inch] });
    
            skSolve(sketch1);
    
            opExtrude(context, id + "extrude1", {
                        "entities" : qCreatedBy(id + "sketch1", EntityType.FACE),
                        "direction" : face.normal,
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : 1 * inch
                    });

    Senior Director, Technical Services, EMEA
  • thomas_allsup
    thomas_allsup Member, User Group Leader Posts: 4 ✭
    Wow - that fixed it and it makes complete sense.  I have to get queries straight.  THANKS!!!!

  • Jake_Rosenfeld
    Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646 image
    @NeilCooke @thomas_allsup

    The right thing to do here is to use `newSketch` rather than `newSketchOnPlane`.  The former takes a face query and the latter takes a mathematical definition of a plane.  If you use the former, you will not need to call `evPlane`.

    https://cad.onshape.com/FsDoc/library.html#newSketch-Context-Id-map
    https://cad.onshape.com/FsDoc/library.html#newSketchOnPlane-Context-Id-map
    Jake Rosenfeld - Modeling Team