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.
Drawing lines to a part edge
Hi,
Referring to this image:
The blue lines were manually drawn and it's these that I'm trying to create in FS.
The red line was also manually created to give a centre point and path for a coordinate system with origin at the midpoint of the vertical edge.
The white line is generated by my FS.
My code is as follows:
FeatureScript 2473;
import(path : "onshape/std/common.fs", version : "2473.0");
annotation { "Feature Type Name" : "Lines Test", "Feature Type Description" : "" }
export const linesTest = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Former", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
definition.face is Query;
// HOW can this be found in FS? annotation { "Name" : "Mid Point and Path", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 } definition.midPointAndPath is Query; annotation { "Name" : "Line Angle" } isAngle(definition.lineAngle, ANGLE_360_BOUNDS); } { const face = definition.face; var endPoints is Query = qAdjacent(definition.midPointAndPath, AdjacencyType.VERTEX, EntityType.VERTEX); var startPosition is Vector = evVertexPoint(context, { "vertex" : qNthElement(endPoints, 0) }); var endPosition is Vector = evVertexPoint(context, { "vertex" : qNthElement(endPoints, 1) }); var xDirection is Vector = normalize(endPosition - startPosition); var zDirection is Vector = evOwnerSketchPlane(context, { "entity" : definition.midPointAndPath }).normal; var cSys is CoordSystem = coordSystem(startPosition, xDirection, zDirection); var sketchPlane is Plane = plane(cSys); // plane with origin at mid point of vertical edge var sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : sketchPlane }); // draw a line from origin to curved edge at passed angle - HOW? const lineEndPoints is map = skLineSegment(sketch1, "line1", { "start" : vector(0, 0) * inch, "end" : vector(1, 1) * inch }); println(lineEndPoints); skSolve(sketch1); });
I have two questions currently:
- Is it possible to create the midpoint / path (red line) for the coordinate system via code? I have code (not shown above) which finds the vertical edge and calculates the distance along that edge to the midpoint but I couldn't see what to do after that?
- How do I replicate the manually drawn blue lines in FS? I have other code which finds the curved edge on the sketch face but as there doesn't appear to be sketch intersect or use functions(?) I'm not sure how to proceed.
Any help appreciated.
Thank you.
Answers
Finding the midpoint of an edge, just use evEdgeTangentLine with the parameter set to 0.5. This gives you both the direction of the edge and the midpoint which can be used to find red. Using the "face" parameter for the adjacent face can also help make the direction predictable, just in case its flipped the opposite to what you are expecting.
For the blue lines, assuming you know the direction and just want the end point, I would just use evDistance with a line() and the edge. The sides[].point in the result will give you where they intersect, assuming that they do. If they don't the distance will be > 0.
Custom FeatureScript and Onshape Integrated Applications
Thank you for this.
For the blue lines are you recommending drawing a short line at the required angle, then getting the distance from one of its vertices to the edge before drawing a full length line of the measured distance?
You dont have to draw any geometry. evDistance will take in a line definition (same with plane and just a point vector).
ie,
evDistance(context, {
"side0" : outsideEdge,
"side1" : line(midpoint,blueDirection)
});
Custom FeatureScript and Onshape Integrated Applications
Hi,
I think I've followed your advice but:
Would you mind taking a look at my test document please?
https://cad.onshape.com/documents/3e85165d0f12889500446edc/w/ec21dcdf00dfaa1c38ec9fa5/e/b0a5a3049debbdfcca38288f
Any further help appreciated.
Thank you.
2. In your code, it just looks like your units are messed up for the sketch segment on line 108.
In distance result, the "point" has units, so you can remove *meter, except you also need to transfer the point from the world coordinate system to your sketch. You should use worldToPlane to translate your world point into a point in the coordinate system of your sketch plane to ensure that its at the correct location.
One more tip, if you are just drawing straight lines, I prefer using opFitSpline with only 2 points . It drawings a line between the two points without needing to create a sketch or do all the extra work. Especially when you are already working with world coordinate points. Not sure if that helps with what you are doing.
Custom FeatureScript and Onshape Integrated Applications
Thank you I’ll work through those suggestions.
My use case is working towards replicating the image below:
A fuselage former for an RC plane where the longerons are set at given angles defined by my blue lines.
I will therefor need a sketch to draw the longeron sections for lofting, I assume this means I cannot use opFitSpline?
I think I done everything other than working out the zDirection correctly - currently hardcoded - any help appreciated on that.
I'm not sure if I've taken the long way round and if there are efficiencies which could be made - again I'd appreciate any comments.
Thank you.