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.

How can I create string variables?

daniel_baileydaniel_bailey Member Posts: 7
edited April 2017 in Community Support
I have a featurescript feature that takes a string as a precondition.
Is it possible to define a variable that is a string that I can pass into this feature?

I've tried setting the value of a variable to be something quoted in double quotes and single quotes, neither of these is accepted.

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    as far as I know you can't set string value to a part studio variable, but you can pass to feature script the name of a variable as string
  • daniel_baileydaniel_bailey Member Posts: 7
    Hmm, okay then, I've added the feature request tag. This would be really useful for me.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    There is work in progress to remove the type restrictions on variables, so our intent is that you will be able to use strings, arrays, maps, even functions (lambdas).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    There is work in progress to remove the type restrictions on variables, so our intent is that you will be able to use strings, arrays, maps, even functions (lambdas).
    Now that is splendid news.  Thankyou :)

    Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
    @ilya_baran Lambda functions in variables... this sounds fun!
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    @leon_poot You can already put a lambda into a variable with a custom feature.  What we plan to add is the ability to put it in a variable in a Part Studio directly.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • john_mcclaryjohn_mcclary Member, Developers Posts: 3,932 PRO
    @leon_poot You can already put a lambda into a variable with a custom feature.  What we plan to add is the ability to put it in a variable in a Part Studio directly.
    nice

    will that mean we can have logical if statements (if..else..while) inside the variable's lambda function?
    or is the lambda function limited?

    I've rarely used lambda's in C#, so they are still kinda short hand (in-line) tricks to me...
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    The lambda can contain arbitrary FeatureScript code (so yes, if-else, loops, variables).  Though if you are going to be defining non-trivial lambdas, I would recommend putting them in a custom feature, like this: https://cad.onshape.com/documents/9307925f33961a9f1b10c559/w/8cd40e21db8c1060b315e72f/e/0801bef9707f10c6cf75635f
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.