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.

Using Variables in text

mark_morgenmark_morgen Member Posts: 12
I could not get text to work at all with a #variable.  I tried for over an hour, but nothing worked.  My goal is to emboss a text string that includes a single dimension of the part onto a face, such as "Cube Height is #Height inches".  It only works as a simple text string, but I want to update the text automatically when the dimension is changed in the drawing.
I used Onshape instructions, but they failed me...

Thank you!

Answers

  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 419
    edited July 19
    It isn't obvious, but you can right-click in the text box and select "Convert to expression."  But you're not done there.  If you put in #height, Onshape won't like it.  You'll want something like
    "Cube Height is " ~ toString(#height/in) ~ " inches"

  • mark_morgenmark_morgen Member Posts: 12
    I got the value to display using toString, but it's not updating the text when the #height variable changes with drawing changes
  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 419
    make sure the #height variable is above the text sketch in the Features list.
  • _anton_anton Member, Onshape Employees Posts: 410
    Working fine for me. Are you committing your text dialog and your sketch? Can you share your document? I'm only aware of one bug in this functionality, which shouldn't be relevant unless you're working with feature patterns.
  • mark_morgenmark_morgen Member Posts: 12

    I don't know what _anton means by "committing your text dialog and your sketch".

    The text in question is the last variable in the Features List called #TextForSpoolFace, which followed by Plane 2, where the text is defined in Sketch "Face Cutout Shapes".
    When editing the text, and I convert between text and expression, the expression toString(#TextForSpoolFace) is lost as soon as it's converted to text.  Changing the first parameter in the Features List, #SpoolMinBtwnFaces, will change the value for #TextForSpoolFace.  I tried a few workarounds to simplify the expression used in the text editing box, but nothing has worked.

    Thank you for your help with this.  It's been frustrating!

    As long as we're here, where can I find the list of functions like Round, toString, etc.?
  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 419
    Anton means clicking the green check box. 

    Don't convert it back to text.  Leave it as an expression.  And, since your variable is just a number, 

    toString(#TextForSpoolFace)

    is sufficient.

    I don't know if all of the FeatureScript math functions will work in a text box, but here is a good list of math functions:
    https://cad.onshape.com/FsDoc/library.html#module-math.fs
  • mark_morgenmark_morgen Member Posts: 12
    if I leave it as an expression (on the expression line, right justified), the text in my sketch shows up as the expression, not the value of the expression.  So the text will display "toString(#TextForSpoolFace)", not "21.5"
  • mark_morgenmark_morgen Member Posts: 12
    Well, it's working now.  I can't say that I did anything different than before.  The text box now shows the correct value using the toString command... which is what I've been trying all along.
    Thank you for drudging through this with me!
Sign In or Register to comment.