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.
Setting an array of variables
Dylan_Stewart
Member, Developers Posts: 107 PRO
I am working on a project that would allow the user to set any number of variables they choose.
I am trying to follow the small example in the 'Feature UI' section in the FeatureScript guide and need some help understanding what is going on.
I'm thinking maybe something like this
As always, any and all help is appreciated.
Also, a working sample document of the example given in the FsDoc would really help me understand what is going on.
Thank you.
I am trying to follow the small example in the 'Feature UI' section in the FeatureScript guide and need some help understanding what is going on.
I'm thinking maybe something like this
annotation { "Name" : "Variables", "Variable Name" : ".....", } definition.array is array; for (var variables in definition.array) { annotation { "Name" : "My String" } definition.myString is string; annotation { "Name" : definition.myString } isLength(definition.myLength, LENGTH_BOUNDS); }I'm not sure if something like this is possible.
As always, any and all help is appreciated.
Also, a working sample document of the example given in the FsDoc would really help me understand what is going on.
Thank you.
Digital Engineering
0
Comments
This is totally possible. Information about array parameters can be found in the following doc under 'arrays':
https://cad.onshape.com/FsDoc/uispec.html
Your code looks good! You need to change the annotation on the array parameter itself, and define the values in the for loop as 'variable.something' instead of 'definition.something'
Here is an example:
https://cad.onshape.com/documents/85ead7e8198b48c695b39b58/w/4fb966357258b36a88ac0430/e/4eb384334534b70122d7481c
Also, if you press the 'parameter' dropdown (the one with the 'p') and click "array parameter" it will autofill a skeleton for you.
What you're trying to do is still possible though. Making a sample now.
Is this kind of what you're getting at?
Owen S.
HWM-Water Ltd
@Jake_RosenfeldI I just tried to add your feature to my toolbar but OnS reports there are no features to add. If the document is copied first then it works fine. Do you have a sharing permission set that blocks linking directly to your feature?
Cheers, Owen S.
HWM-Water Ltd
Best,
Mike
Cheers, Owen S,
HWM-Water Ltd
I think there is a small bug in your FS. It seems to work for all values of an array except the last one.
Examples
(a) I made a feature with 2 options. Option 1 worked, option 2 failed
(b) Straight copy of your doc. The example has 3 options, 1 and 2 work, 3 fails.
Could you give it a poke?
Cheers,
Owen S.
HWM-Water Ltd
Have you taken a different approach?
Sorry my approach was to add @Jake_Rosenfeld's feature to my toolbar
Wish I could be of more help.
Owen S.
HWM-Water Ltd
The options are 0-indexed. So the first option is option 0, the second option is option 1 etc. Just a byproduct of working on code all day
Would it be better for you guys if it was one-indexed?
Write it in Hex if it makes you happy!
Cheers,
Owen S.
HWM-Water Ltd
I've added a V2 to the feature that has better error handling and a choice for 0 and 1 indexing.
Also love the update feature notification and process. it's clear a lot of thought has gone into this area.
Cheers, Owen S.
HWM-Water Ltd