Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

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!

Best Answer

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    opTransform moves bodies, it's not a sketch operation like skRectangle. Since sketches don't create any geometry until skSolve is called, this means you need to call opTransform after you call skSolve.

    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.
    opTransform(context, id + "transformId", {
        "bodies" : sketchEntityQuery(id + "sketchId", EntityType.BODY, "sketchEntityId"),
        "transform" : transform(vector(1, 2, 3) * inch) * rotationAround(Z_AXIS, 30 * degree)
    })
    ...replacing the ids and the transform with something sensible, and calling it in a second loop, after skSolve :smile:

    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!
  • joshua_smith082joshua_smith082 Member Posts: 4
    This seems to get complicated quickly. Is there a simpler way to rotate the coordinate system before the skText so the text can be placed in its final orientation? And also allow all the text to be in 1 sketch?
Sign In or Register to comment.