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.
Help rotating text in FeatureScript
joshua_smith082
Member Posts: 4 ✭
Perhaps I'm on the wrong path, or not...
Ive created a featurescript to make an array of holes. I want to add labels (text) to the holes but I cant seem to figure the best way to rotate the text so it is aligned to the holes. The following FS is my work in progress:
https://cad.onshape.com/documents/2c1eadc57cd2c7105b8cedd8/w/d505b2332d6778c33525b527/e/4d5be0106e3b7bebd2c1c68c
the TEXT section starts on line 235. I know that the ID for the skText is wrong as it seems to want a string rather than an ID. Is there a better way rather than using the transform? I thought to maybe move and rotate the coordinate system, draw the text, and pop back to previous coordinates but I havent found any examples of doing that in FS.
edit: I reverted the skText back to where it functions, and commented out the transform as it doesnt work (qCreatedBy wants an ID, not string)
Thanks for reading!
Ive created a featurescript to make an array of holes. I want to add labels (text) to the holes but I cant seem to figure the best way to rotate the text so it is aligned to the holes. The following FS is my work in progress:
https://cad.onshape.com/documents/2c1eadc57cd2c7105b8cedd8/w/d505b2332d6778c33525b527/e/4d5be0106e3b7bebd2c1c68c
the TEXT section starts on line 235. I know that the ID for the skText is wrong as it seems to want a string rather than an ID. Is there a better way rather than using the transform? I thought to maybe move and rotate the coordinate system, draw the text, and pop back to previous coordinates but I havent found any examples of doing that in FS.
edit: I reverted the skText back to where it functions, and commented out the transform as it doesnt work (qCreatedBy wants an ID, not string)
Thanks for reading!
Tagged:
0
Best Answer
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Why do you need it to be one sketch operation? Looking again at your case, if you want simple code I really would suggest simply making a new sketch for each entity. The overhead making each sketch is quite small (which you can verify with the FeatureScript profiler).
This change would just mean replacing each of your current calls to skText with something more like:const angle = 30 * degree; const textCoordinateSystem = coordSystem(WORLD_ORIGIN, vector(cos(angle), sin(angle), 0), Z_DIRECTION); var sketch1 = newSketchOnPlane(context, id + i + "sketch", { "sketchPlane" : plane(textCoordinateSystem) }); skText(sketch1, "textId", { "text" : "dtext", "fontName" : "RobotoSlab-Regular.ttf", "firstCorner" : vector(x, y) * inch, "secondCorner" : vector(x+1, y+1) * inch }); skSolve(sketch1); </code>const angle = 30 * degree; var sketch1 = newSketchOnPlane(context, id + i + "sketch", { "sketchPlane" : plane(WORLD_COORD_SYSTEM) }); skText(sketch1, "textId", { "text" : "dtext", "fontName" : "RobotoSlab-Regular.ttf", "firstCorner" : vector(x, y) * inch, "secondCorner" : vector(x+1, y+1) * inch }); skSolve(sketch1); opTransform(context, id + i + "transform", { "bodies" : qCreatedBy(id + "sketch1", EntityType.BODY), "transform" : rotationAround(Z_AXIS, angle) }); </pre><div>Completely equivalently, you could avoid calling opTransform entirely by setting the correct coordinate system to on each sketch to begin with:</div><pre class="CodeBlock"><code>
Both solutions keep the placement logic for each hole in one place instead of two.5
Answers
One easy way to do this is to make a sketch for each bit of text and transform each sketch. Here's an old example doing that:
https://cad.onshape.com/documents/cdbad61ec176b39049f8d4c1/w/0cb06ca7cb2788345cc7a448/e/e11a12cb6c7c926bdab162a0
If you want to keep one sketch, you'll instead want to select individual sketch entities with sketchEntityQuery, e.g.
...replacing the ids and the transform with something sensible, and calling it in a second loop, after skSolve
Sidebar: transform and opTransform do the same thing, but "transform" is a feature whose parameters were designed for use as a feature, while opTransform is a function designed to call from FeatureScript. In practice you can use either but opTransform is more flexible.
Hope that helps!
This change would just mean replacing each of your current calls to skText with something more like: