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 Variable

papawopapawo Member, Developers Posts: 206 PRO
is it possible to make a text variable if a dimension of a part becomes diff?
ex. text1 = if the hole is 1" dia; 
      text2=if the hole is 2" dia

Comments

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    there exist conditional expression syntax like condition?value_if_true:value_if_false
    but now we have configurations so seems like defining several rows of config table for two parameters is a better approach
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    If you want to use the conditional route, then it would look something like this.

    First, the hole diameter needs to be controlled or at least linked to a variable (#Hole_Dia).

    Then, your #Hole_Text would be set to the following:
    #Hole_Dia<10mm?"Small Hole":"Big Hole"

    So if the hole is less than 10mm, the text would read "Small Hole". If it's equal to or larger than 10mm, the text will be "Large Hole".
  • papawopapawo Member, Developers Posts: 206 PRO
    can I put formula in configuration? 
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited January 2018
    if i'm not mistaken currently there is no way to make something useful with text expressions, there are no features that can process it correctly and text fields of feature table beahve the same way so if you assign a result of text expression to variable and feed that variable to the feature like Surface text it wouldn't print the value of variable but just its name
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    But you could input the actual expression into an "Any" field of of a feature or FS, no?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited January 2018
    mahir said:
    But you could input the actual expression into an "Any" field of of a feature or FS, no?
    the problem is that field of "any" type only exists in variable defenition builtin feature, so you can't pass text expression to the geometry level of feature studio. several days ago i made a request to Dave Cowden for optional support of isAnything() predicate in his Surface text FS, and somewhere on the forum Ilya Baran posted a link to the rewrapped Surface text feature with support of isAnything
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    I don't pretend to know what goes on under the hood, but OS recently made some changes to isAnything that made my Parametric Curve FS work pretty well without workarounds. I thought expression parsing was standard now?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited January 2018
    mahir said:
    I thought expression parsing was standard now?
    it works good but currently there are no features that support text expression input. they all have input fields of string type, except one by Ilya
  • mahirmahir Member, Developers Posts: 1,307 ✭✭✭✭✭
    Ah, gotcha.
  • papawopapawo Member, Developers Posts: 206 PRO
    I am trying to control the part naming according to the variation of parts. i dont want to just name it . i want to have a check or formula that will name the part. anyone can tell me if its possible?
  • papawopapawo Member, Developers Posts: 206 PRO
    not exactly what i want.

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @Nan_Cp

    You cannot currently change the name of the part in FeatureScript, but this is coming soon.  Stay tuned to the update announcements.
    Jake Rosenfeld - Modeling Team
  • matthew_stacymatthew_stacy Member Posts: 487 PRO
    @ilya_baran thanks so much for that ST Surface Text (Expression-based) feature-script!  I was looking for something exactly like that, to allow users to configure a label on a part (shared document).  And thanks to @konstantin_shiriazdanov for providing the link (Jan. 2018).

    The user community is a fantastic aspect of the Onshape platform. Seeing so many intelligent people generously sharing ideas restores my faith in humanity.

  • matthew_stacymatthew_stacy Member Posts: 487 PRO
    So the ST Surface Text (Expression-based) feature script works great for creating surface text from text variables.  Is there a way to do this with numeric variables?

    This url is for a part with configuration variables for a text string and two dimensions (numeric).  I would like to generate surface text from the text string (√ done) AND generate more surface text to label the part with its dimensions (x & y).

    If there is a way to create surface text from numeric variables, it is then possible to concatenate a string from characters and numeric data (e.g. create the string "(100mm x 40mm)" based on the values of x & y?

    Ideas?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,212
    @matthew_stacy
    It's doable, but it's a slightly tricky expression.  The string concatenation operator in FeatureScript is ~.  You also want to use the roundToPrecision function to avoid too many significant figures.  For the string you asked for, with 3 significant figures, you end up with something like this:
    "(" ~ roundToPrecision(#x / mm, 3) ~ "mm x " ~ roundToPrecision(#y / mm, 3) ~ "mm)"

    You can also debug intermediate subexpressions by assigning them to "any" type variables -- in other words, you can create a variable xString of type "any" with the expression
    roundToPrecision(#x / mm, 3) ~ "mm"
    and then use #xString and similarly #yString in the text field

    Hope this helps.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • matthew_stacymatthew_stacy Member Posts: 487 PRO
    Thanks for the syntax lesson @ilya_baran.  Greatly appreciated.
  • david_santopietrodavid_santopietro Member, csevp Posts: 2 PRO
    @papawo, did you find a solution?

    I reached out to Onshape support about same issue and they lead me to this: 

    https://cad.onshape.com/documents/3a320c371e27789f9e7681bc/w/b639c9809964f0ef281ad6cf/e/ae295a8e774ff3beff1948e2

    This kind of resolves the problem. Happy to discuss in more depth. 
Sign In or Register to comment.