Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
FS to create planes from Sketch inside the same FS
Dylan_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:
------------------------------------------------------------------------------------------------------------
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
});
I hope this makes sense.
Any and all help, guidance and direction is greatly appreciated.
---------------------------------------------------------------------------------------------------------------------------------------------
// 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
0
Comments
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:
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.
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.
PhD, Mechanical Engineering, Stanford University
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);
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.
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.
PhD, Mechanical Engineering, Stanford University
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.
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)
PhD, Mechanical Engineering, Stanford University