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

FS to create planes from Sketch inside the same FS

Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
Okay, I will try and explain this to the best of my ability. 

I am creating a FS that creates a simple sketch with vectors and skLineSegmants. 
What I would like to have is to select a point on the end of a few of the lines and create planes to add say a skCirlce.

This is an example of my workflow:
------------------------------------------------------------------------------------------------------------
FeatureScript 392;
import(path : "onshape/std/geometry.fs", version : "392.0");

export enum OverAllLength
{
    annotation { "Name" : "24 inch" }
    ONE
}
annotation { "Feature Type Name" : "Ladder Pull" }
export const ladderPull = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "My Enum" }
        definition.pullLength is OverAllLength;
    }
            var radius = .625 * inch;
            var ladderPullSizeFinal = ladderPullSize;
            var midPostLength = 2.4375 * inch;
            var botMidPost = (ladderPullSize - midPostSpacing) / 2;
            var topMidPost = botMidPost + midPostSpacing;
            var pullVerticies = [vector(0, 0) * inch, vector(0 * inch, ladderPullSizeFinal), vector(0 * inch, botMidPost), vector(midPostLength, botMidPost),                         vector(-1.5 * inch, topMidPost),
            vector(midPostLength, topMidPost)];
            var skeletonSketch = newSketch(context, id + "skeletonSketch", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });

            skLineSegment(skeletonSketch, "LadderLength", {
                        "start" : pullVerticies[0],
                        "end" : pullVerticies[1]
                    });
            skLineSegment(skeletonSketch, "BotMidPost", {
                        "start" : pullVerticies[2],
                        "end" : pullVerticies[3]
                    });
            skLineSegment(skeletonSketch, "TopMidPost", {
                        "start" : pullVerticies[4],
                        "end" : pullVerticies[5]
                    });
            skSolve(skeletonSketch);

            var radiuSketch = newSketch(context, id + "radiusSketch", {
                    "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
                });
            skCircle(radiuSketch, "circle1", {
                        "center" : vector(0, 0) * inch,
                        "radius" : radius
                    });
            skSolve(radiuSketch);
            
            var circleQuery = sketchEntityQuery(id + "radiusSketch", EntityType.BODY, "circle1");
            var cirlceLine = evLength(context, {
                    "entities" : circleQuery
                });

            var extrudeRegion = qSketchRegion(id + "radiusSketch");
            extrude(context, id + "extrude1", {
                        "entities" : extrudeRegion,
                        "endBound" : BoundingType.BLIND,
                        "depth" : ladderPullSizeFinal
                    });
            debug(context, extrudeRegion);
---------------------------------------------------------------------------------------------------------------------------------------------
// This is what I'm working on

            var botEndPointQuery = sketchEntityQuery(id + "skeletonSketch", EntityType.VERTEX, "BotMidPost");
            var botMidPostLine = evLength(context, {
                    "entities" : botEndPointQuery
            });
            
            var pointRegion = qSketchRegion(id + "skeletonSketch");
            opPlane(context, id + "opPlane1", {
                    "plane" : pointRegion,
                    "width" : 6 * inch,
                    "height" : 6 * inch
            });

});

I hope this makes sense. 

Any and all help, guidance and direction is greatly appreciated.
Digital Engineering

Comments

  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    something like this
    Digital Engineering
  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited August 2016
    To directly answer, you can create that sketch by calling newSketchOnPlane on with the plane being something like
    plane(origin, normal);

    However, I think for your needs you don't even need sketches and planes. If you are generating cylinders, the easiest way is to just call fCylinder.

    For example:
    var ladderPlane is Plane = evPlane(context, {
            "face" : qCreatedBy(makeId("Front"), EntityType.FACE)
        });
    var pullVerticies = [
        vector(0, 0) * inch,
        vector(0 * inch, ladderPullSizeFinal),
        vector(0 * inch, botMidPost),
        vector(midPostLength, botMidPost),
        vector(-1.5 * inch, topMidPost),
        vector(midPostLength, topMidPost)
    ];
    var pullVertices3d = mapArray(pullVerticies, function(vertex) {
        return planeToWorld(ladderPlane, vertex);
    });
    
    fCylinder(context, id + "cylinder1", {
            "topCenter" : pullVertices3d[0],
            "bottomCenter" : pullVertices3d[1],
            "radius" : radius
    });
    fCylinder(context, id + "cylinder2", {
            "topCenter" : pullVertices3d[2],
            "bottomCenter" : pullVertices3d[3],
            "radius" : radius
    });
    fCylinder(context, id + "cylinder3", {
            "topCenter" : pullVertices3d[4],
            "bottomCenter" : pullVertices3d[5],
            "radius" : radius
    });
    Which generates this:


    Document with my changes in your code:
    https://cad.onshape.com/documents/a7de68a6f916b5b55f121b0a/w/2972f8a4eccaf9a731c20af1/e/7de07bafbfefbaeba1b9e97a

    For future readers: fCylinder, under the hood, does perform an extrude in Onshape. Eventually, we will have a function named opCylinder which will do the same thing, but by creating the primitive directly, which will have better performance and be even more preferred in a case like this.
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @kevin_o_toole_1

    That's exactly what I'm looking for!! Thank you so much.

    The reason I wanted to use plans is to be able to call this FS while using other FS....

    I wanted to create a door using Height/Width/Depth/DoorHandlePlacement

    My thought process is that this is basically married to the origin plane?? So I wanted to name the 'new planes' so that they might be mated to the door planes for mounting purposes. 

    Is this achievable? 

    I understand that it would be very easy to do in an assembly, but I would like to avoid doing that.
    Digital Engineering
  • Options
    lemon1324lemon1324 Member, Developers Posts: 223 EDU
    The reason I wanted to use plans is to be able to call this FS while using other FS....

    ...

    My thought process is that this is basically married to the origin plane??
    If you write the relevant code as a function, you could always provide an input to define the coordinate system in which you want to create the features, and therefore be able to use fCylinder and calculated coordinates instead of having to calculate and create many planes. That would let you have a generalized FS that could be called from other places.

    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    I'm not sure from that description how you want you FS to behave/interact. Perhaps a sketch/diagram would be helpful?

    To get my script above to create that geometry in a different location, you can change the Plane variable to a plane of any coordinate system you want, e.g.
    var ladderPlane is Plane = plane(myOrigin, myNormalDirection, myXdirection);

  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Very useful information @lemon1324 but I am trying to have absolutely everything in one feature. 

    With this bit of code I can only create one door pull, I still need to create a plane from the face of cylinder to have something to reference a 'door thickness' and mirror this door pull so that it'll be on the other side of the door. 

    I know all of these things can be done manually, but this is something I wish to avoid. Also, this is not going to be the only option of door pull. 

    My UX is going to look something like this:
    Have the user enter Width/Height/Thickness
    I will have menus set up to choose which door handles/pulls the user would like
    and depending on which handle they pick, it will create mounting holes in the door accordingly.
    It will also space the mirrored door pull/handle according to the users input on door thickness.
    Digital Engineering
  • Options
    lemon1324lemon1324 Member, Developers Posts: 223 EDU
    @Dylan_Stewart, Having everything in one user-visible feature doesn't mean you can't have things organized into smaller functions behind the scenes--it's usually easier to debug if you do.

    In this case, I'd consider writing a feature (or just a function, as long as you pass context and id) that just makes a door pull given a location to put it. You can then debug this manually without having to write the door/hole generation/mirroring code.  When you write the top-level feature, you can then call this door-pull-generating feature from inside your other feature, passing inputs appropriately.
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @lemon1324  That sounds great!!!

    I guess my exp in coding is not near as strong as I thought. 
    If you could provide me an example, I'm sure I could figure it out from there. 
    Digital Engineering
  • Options
    lemon1324lemon1324 Member, Developers Posts: 223 EDU
    @Dylan_Stewart the Laser Joint feature I wrote has several helper functions to help organize and make code more reusable.  It's reasonably well commented, but is probably on the more complicated side for FS.

    T-Slot joints is still a work in progress, but is probably closer to what you're looking for; note how I first calculate positions based on input parameters, and then call a function to generate geometry at each point.

    (apologies for only linking to my own stuff, but it's what came to mind first.  Similar stuff is also in the FS Source provided by Onshape, but those are more complicated to read)
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
Sign In or Register to comment.