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.
Using Arrays with Variables
Dylan_Stewart
Member, Developers Posts: 107 PRO
I am having a difficult time trying to accomplish a sort of "option" selection with a variable driven model.
This is what I have so far.
#option = "number"
#customWidth = "length"
#width = [10,20,30,40,50,#customWidth][#option]
#customHeight = "length"
#height = [30,40,50,60,70,#customHeight][#option]
I'm trying to sketch a cube using the variables where
Width dimension = #option<=4?#width: (#option=5?#customWidth))
Height dimension = #option<=4?#widht: (#option=5?#customHeight))
There might be an obvious reason this is not working....?
Here is the link to the document.
https://cad.onshape.com/documents/895e301bfebbbd68e10e7cbe/w/80a786217c7f4b8c6a9c92e4/e/a192d6f7e85074b279afb60c
This is what I have so far.
#option = "number"
#customWidth = "length"
#width = [10,20,30,40,50,#customWidth][#option]
#customHeight = "length"
#height = [30,40,50,60,70,#customHeight][#option]
I'm trying to sketch a cube using the variables where
Width dimension = #option<=4?#width: (#option=5?#customWidth))
Height dimension = #option<=4?#widht: (#option=5?#customHeight))
There might be an obvious reason this is not working....?
Here is the link to the document.
https://cad.onshape.com/documents/895e301bfebbbd68e10e7cbe/w/80a786217c7f4b8c6a9c92e4/e/a192d6f7e85074b279afb60c
Digital Engineering
0
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646Dylan and I solved this together in the document!
For everyone else:
The original definition was set up like:#option = 5 #customWidth = 10 in #width = [10, 20, 30, 40, 50, #customWidth][#option] in
But if option 5 was selected, the whole thing broke because resolving option 5 gives "10 in in"
Solved by changing to:#option = 5 #customWidthInInches = 10 #width = [10, 20, 30, 40, 50, #customWidthInInches][#option] in
Edit: After going and making sure it works as expected, I think a better solution is:#option = 5 #customWidth = 10 in #width = [10 in, 20 in, 30 in, 40 in, 50 in, #customWidth][#option]
Jake Rosenfeld - Modeling Team5
Answers
Is this even possible in OS?
For everyone else:
The original definition was set up like:
But if option 5 was selected, the whole thing broke because resolving option 5 gives "10 in in"
Solved by changing to:
Edit: After going and making sure it works as expected, I think a better solution is: