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.
Im having trouble understanding how sketch features read data...
darren_13
Member, Developers Posts: 117 PRO
So I thought I had overcome the learning curve but appears not:
Basically i want to draw a line from point A to point B (seems simple but its part of a more complex program) using defined points from the user.
Basically i want to draw a line from point A to point B (seems simple but its part of a more complex program) using defined points from the user.
annotation { "Name" : "Select Leading Edge", "Filter" : EntityType.VERTEX && SketchObject.YES, "MaxNumberOfPicks" : 1 }
definition.leadingEdge is Query;
annotation { "Name" : "Select Trailing Edge", "Filter" : EntityType.VERTEX && SketchObject.YES, "MaxNumberOfPicks" : 1 }
definition.trailingEdge is Query;
skLineSegment(sketch, "cord", { "start" : evVertexPoint(context, {
"vertex": definition.leadingEdge}),
"end" : evVertexPoint(context, {
"vertex" : definition.trailingEdge})
});
returns error:
Precondition (value.start is undefined  is2dPoint(value.start)) of skLineSegment failed
Previously got this working by drawing an arbitrary line and coinciding them to the said points which worked using qUnion as the external second coincidence however it felt like I was bypassing my misunderstanding instead of tackling it.
A little help would be much appreciated
Sorry for the basic Question but I need to start somewhere!
Many Thanks
Darren Lynch
returns error:
Precondition (value.start is undefined  is2dPoint(value.start)) of skLineSegment failed
Previously got this working by drawing an arbitrary line and coinciding them to the said points which worked using qUnion as the external second coincidence however it felt like I was bypassing my misunderstanding instead of tackling it.
A little help would be much appreciated
Sorry for the basic Question but I need to start somewhere!
Many Thanks
Darren Lynch
Tagged:
0
Best Answer

kevin_o_toole_1 Posts: 446The error you're seeing is from the precondition to
skLineSegment()
, which is expecting the statement displayed in parentheses to be true (i.e. if you've defined a "start", it should be a 2D point). Specifically, it wants a point defined in the sketch's coordinate system.
The result ofevVertexPoint()
is a 3d Vector in world space. You can get the start point into plane space by callingresize(planeToWorld(sketchPlane, startPoint), 2))
, but there's probably an cleaner way.
You didn't mention how you definedsketch
, or its plane. If you want to draw a line between two points, you'll be happiest defining the sketch plane such that its xaxis lies along the line you wish to draw. That way, it's easy to construct the two points you need in the sketch's coordinates.
Here's a minimal example which creates a sketch line on a sketch between two points as described. The sketch plane is an arbitrary plane containing the line (i.e. whose normal is defined byperpendicularVector
).const point1 is Vector = evVertexPoint(context, {
"vertex" : definition.leadingEdge
});
const point2 is Vector = evVertexPoint(context, {
"vertex" : definition.trailingEdge
});
const length is ValueWithUnits = norm(point2  point1);
const orth is Vector = perpendicularVector(point2  point1);
const sketch1 = newSketchOnPlane(context, id + "sketch1", {
"sketchPlane" : plane(point1, orth, point2  point1)
});
skLineSegment(sketch1, "line1", {
"start" : vector(0, 0) * meter,
"end" : vector(length, 0 * meter)
});
skSolve(sketch1);5
Answers
skLineSegment()
, which is expecting the statement displayed in parentheses to be true (i.e. if you've defined a "start", it should be a 2D point). Specifically, it wants a point defined in the sketch's coordinate system.The result of
evVertexPoint()
is a 3d Vector in world space. You can get the start point into plane space by callingresize(planeToWorld(sketchPlane, startPoint), 2))
, but there's probably an cleaner way.You didn't mention how you defined
sketch
, or its plane. If you want to draw a line between two points, you'll be happiest defining the sketch plane such that its xaxis lies along the line you wish to draw. That way, it's easy to construct the two points you need in the sketch's coordinates.Here's a minimal example which creates a sketch line on a sketch between two points as described. The sketch plane is an arbitrary plane containing the line (i.e. whose normal is defined by
perpendicularVector
).