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.
Orient a sketch
fma
Member Posts: 87 ✭✭
Hi!
I'm writing a FeatureScript to help designing repetitive tasks for metal sheet lasercut:
https://cad.onshape.com/documents/9fcacffa14bbcb794a372061/w/1cf9683d04a93c666f667b13/e/66c6c1aab8f0abe0ba69579d
This idea of this script is to generate the M3 nut trap for the assembly. See this for usage:
https://cad.onshape.com/documents/9fcacffa14bbcb794a372061/w/1cf9683d04a93c666f667b13/e/27132e161bac5e17cedb66ba
I generate the cut profile with a polyline, but I need to turn it so the cut is normal to the edge of the part. How can I automatically orient the polyline sketch? are the selected point/part enough the do that?
Thanks for your help.
I'm writing a FeatureScript to help designing repetitive tasks for metal sheet lasercut:
https://cad.onshape.com/documents/9fcacffa14bbcb794a372061/w/1cf9683d04a93c666f667b13/e/66c6c1aab8f0abe0ba69579d
This idea of this script is to generate the M3 nut trap for the assembly. See this for usage:
https://cad.onshape.com/documents/9fcacffa14bbcb794a372061/w/1cf9683d04a93c666f667b13/e/27132e161bac5e17cedb66ba
I generate the cut profile with a polyline, but I need to turn it so the cut is normal to the edge of the part. How can I automatically orient the polyline sketch? are the selected point/part enough the do that?
Thanks for your help.
0
Comments
If you create the sketch with newSketchOnPlane() than you can control coordinate system of the sketch plane. Align xDir of the plane with the direction of the edge (or normal to it).
Alternative is to use opTransform on bodies created by sketch (qCreatedBy(id + "sketch1", EntityType.BODY) ).
evFaceTangentPlane().normal . If it is an edge, var edgeDir = evEdgeTangentLine().direction would give you edge direction
cross(sketchPlane.normal, edgeDir) will give you direction in sketch plane normal to edgeDir.
Hope now I'm closer to the answer.
Step 1: sketch
step 2: extrusion (metal sheet)
step 3: cut
As you see, I give the vertices and the body to cut. But I don't know how to re-orient my polyline.
(in this function, I give 'vertex' and 'part'):
const center = evVertexPoint(context, {"vertex" : vertex});
It is not ideal, but if it gives you only one edge , that is the edge you want. If we had something like qCreatedByTheSameOp() query, you could've narrowed it down to the sketch supplying the point.
As a way of making your feature more general you can call
evOwnerSketchPlane(context, {'entity' : vertex}); to recover original sketch plane.
And I don't think call opPlane(context, id + "plane1", {"plane": plane1}); is needed.
vertexList = evaluateQuery(vertices);
allEdges = qSketchFilter(qGeometry(qEverything(), GeometryType.LINE), SketchObject.YES);
for vertex in vertexList do
{
zVector = evOwnerSketchPlane(context, vertex);
vertexPoint = evVertexPoint(vertex);
edge = qContainsPoint(allEdges, vertex);
xVector = evLine(context, edge).direction;
workPlane = plane(vertexPoint, zVector, xVector);
....
}
but the xVector is not correctly oriented ; any idea how to retreive the correct direction?
yVector = -filter(evaluateQuery(qEdgeAdjacent(edge, EntityType.FACE)), function(face){
return !parallelVectors(evPlane(face).normal, zVector)})[0];
xVector = cross(yVector, zVector)
wrap the allEdges query above into sheet body filter
var allEdges = qBodyType(qSketchFilter(qGeometry(qEverything(), GeometryType.LINE), SketchObject.YES), BodyType.SHEET);
Once you got the edge:
var face = qEdgeAdjacent(edge, EntityType.FACE);
var edgeDir = evEdgeTangentLine(context , {'edge' : edge, 'parameter' : 0.5, 'face' : face}).direction //will give you "oriented" direction of the edge in the face - face is to the left of the edge.
var xVector = cross(evPlane(face).normal, edgeDir); // Is normal to edge pointing into the face.
Presumably you'll have a 2nd part that bolts perpendicular to the face you have your input vertex on?
If so would it make sense to have the input vertex coincident with the centre line of the bolt's axis rather than the bottom edge? Presumably you'd have that position defined already so it'd be less reference geometry to build. You could also have the feature make the round through hole in the 2nd plate perhaps? (Similar to the cam an dowel FS.)
Just thinking out loud, forgive the intrusion.
Cheers, Owen S.
HWM-Water Ltd
But I don't need to define the bolt axis, and it will be more work to do that. The reason is the parts are lasercut metal sheets. So, a 2D sketch is all we need to define geometry; the width is constant (3mm).
I wanted to write a few 3D tools to move out all boring tasks outside of the sketch, where we only focus on the global assembly. This include:
- M3 nuts trap
- angles cut (for easier assembly)
So, for this script, I only need to put a point on the sketch, where we need to make the M3 nut trap.
Sorry, I'd assumed you were using multi-part modeling in a partstudio, or in context editing from an assembly. So ultimately you could have a single feature that says here's a bunch of points, I want to put a M4 bolts here, with washers, though this part, (so make bolts, washers and through holes) then make the nut cutouts in the other parts and add the nuts.
Owen S.
HWM-Water Ltd
Our next step is to fully constrain the DXF sketches, and start using these 3D tools.
But ultimately, you're right, it would be much better to make a multi-parts PartStudio, et adapt the 3D tools the way you mentioned.
O.S.
HWM-Water Ltd
This is a nice collaborative work, and we have to say that Onshape is really great for such community projects. Most of use started to learn Onshape only a few months ago, and we made this migration in only a few weeks, on our free time. Amazing! I love this software!
Cheers! I'm glad Onshape is working out for you. Thank you for putting time and effort into mastering FeatureScript.
https://forum.onshape.com/discussion/5824/sketch-plane-using-3-vectors#latest