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.
Is there a way to make a copy of a curve or sketch Id
dave_cowden
Member, Developers Posts: 475 ✭✭✭
Suppose we start with a sketch, 'sketchA', which contains a sketched curve.
Is there a way to create a copy of an arc or spline in a new sketch, 'sketchB'?
If the curve I'm trying to copy is a line or arc, I can see it would be possible to manually re-create it using evCurveDefinition, combined with evTangentLines.
But if the provided curve is a spline, I don't know what to do, because evCurveDefinition returns 'unspecified contents'.
I also considered just using evTangentLines and then fitting a spline all the time, but If the original curve is an arc, i dont want to use a spline.
So the best I can come up with is to use evCurveDefinition to create a line or arc, and then if evCurveDefinition returns undefined, fit a spline through points using evTangentLines. But the problem is that this will produce an imperfect replica of the original.
maybe i can use qDependency to get the original sketch.. but that doesnt help me recreate a copy...
Am I making this too hard?
Is there a way to create a copy of an arc or spline in a new sketch, 'sketchB'?
If the curve I'm trying to copy is a line or arc, I can see it would be possible to manually re-create it using evCurveDefinition, combined with evTangentLines.
But if the provided curve is a spline, I don't know what to do, because evCurveDefinition returns 'unspecified contents'.
I also considered just using evTangentLines and then fitting a spline all the time, but If the original curve is an arc, i dont want to use a spline.
So the best I can come up with is to use evCurveDefinition to create a line or arc, and then if evCurveDefinition returns undefined, fit a spline through points using evTangentLines. But the problem is that this will produce an imperfect replica of the original.
maybe i can use qDependency to get the original sketch.. but that doesnt help me recreate a copy...
Am I making this too hard?
0
Answers
For instance, you can use opPattern to create a copy of any body or set of bodies. Does that accomplish what you want? If not, what's your ultimate goal with this feature?
I need to programmatically create a sketch, and then create sketch entities in that sketch, which have constraints based upon geometry that was creates by the user earlier ( IE, a curve).
Op pattern will not work because I need to create sketch entities based on the geometry, not a copy of the entity itself. I need sketch entities because I need to add constraints.
For example, if I have an arc, I don't need a copy of the edge, I need to call skArc.
If it is possible to create constraints in a sketch that reference geometry defined elsewhere, that would be perfect, but I don't know how to do that
Now, if you do want add such a thing to a sketch, I'd take a look at what's done when you project a spline into another sketch in Onshape with the "use" command. In FeatureScript, if you can create the correct entity type in your new sketch (e.g. an arc), and add a projection constraint, that will get you going in the right direction.
skText will initially place text on the sketch origin with a line height of one meter, so you can do the math to move it after the fact to the desired position. As suggested on the opTransform doc, you can scale down using
transform(identityMatrix(3) * scale, vector(0, 0, 0) * inch)
, and you can move to another cSys withtoWorld(cSys)
. Using this method you can create a new sketch for every letter and transform them.Keep posting if you run into further obstacles!
yes, i've gotten some examples working by transforming the letters, roughly as you suggested. When i can pre-compute the points I want , your recommended strategy works.
But in many cases, I cannot pre-compute the coordinates to transform to. Consider I have two letters next to each other. I have no way to know their width-- which is variable. The sketch solver is the best solution-- I can simply constrain the lower right corner of letter 1 to be co-incident with the lower-left corner of letter two. Now the letters stay together, and then I can fix that to any location I want. But where in 3d space? I cannot calculate the point-- because i dont know the width of the letters, and i dont have a way to find it.
If I am placing text on a curve from left to right, i can create text as above, and then fix the lower left corner of the sketch text to be at the start point of the curve. But then, how do i compute coordinates on which to fix the other letter corners? This is impossible because i dont know the letter width.
Thus the need to use the sketch solver....
You can, however, easily determine the bounding box of a letter using evBox3d. For an example of this, here's a public document I made which positions sketch text on a line:
https://cad.onshape.com/documents/cdbad61ec176b39049f8d4c1/w/0cb06ca7cb2788345cc7a448/e/e11a12cb6c7c926bdab162a0
It's only for one letter, but you can imagine doing it for multiple.
Figuring out the final position is also tricky, but: To evaluate the position along a line based on the letter length, you can divide the desired distance by the curve length (evLength), and use that as the parameter for evTangentLine().