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.
Is it possible to import configuration variables as txt file?
joshua_madero
Member Posts: 2 ✭
in General
I have a script in python that finds variables I need to use to design a propeller, like hub diameter, chord lengths, etc. I can export these variables as a file (csv/txt). Is it possible to import this file and automatically create the variables and assign values in Onshape? If you are a Solidworks user, this is just importing equations.
(I haven't started using FeatureScript)
Thanks!
(I haven't started using FeatureScript)
Thanks!
0
Comments
Yea, you can either create a featurescript that accepts a CSV and assigns variables
Or
You can create a featurescript on the fly that just is a list of setVariable(); commands
What I end up doing is I have a spreadsheet that spits out all of the parameters into a cell. Then I have the marketing person copy paste into a super plain featurescript so I don't have to worry about them knowing code.
Then I have a separate FS that gives me global variables when I add it to the feature tree.
Don't worry about the enum eUnit, that was so I can have a bunch of global variables with overrides for different assemblies...
If I had half a clue, I would like this to be derived from a .cvs to make it even easier for the marketing person.
Problem is, then they would need to always export from a spreadsheet when wanting to make minor tweaks.
At least this way I can edit any parameter in the Parameters FS directly.
https://cad.onshape.com/documents/75dfbb9091b5bea038398789/w/20b6cc9fc5923631d05184a8/e/97a921379d1437bdaef7fcdf
Edit2: Ok, fixed bug, didn't realize I needed to check the size of csvData instead of the TableData object. Above code is now correct
Your question got me re-thinking our biggest product's design workflow.
It works pretty well, now the marketing person can click a button and update the csv in Onshape. Making it even more fool proof.
and I didn't have to beg @MBartlett21 for featurescript help this time
By the way, If you need to tweak or do additional operations on any variable that you defined in the CSV
you can add these two lines of code (in red)
Then you can access any of those variables in featurescript like any other map. Example the variable "shingleThickness" was created on line 10 of the spreadsheet, and can be accessed in the featurescript by calling v.shingleThickness
That looks good!
IR for AS/NZS 1100
This is cool and I love the simple code! I'm not sure how to get anything other than unitless values or strings. Should I be able to get the value to equal "1*millimeter" or should I tweak the featurescript?
Onshape will automatically enclose the equation with "(____) in" for inches so I don't even think auto it. start typing the variable in the dimension and let autocomplete finish it.
To add and remove units at any point it is usually as easy as VARIABLE * UNIT to add and VARIABLE / UNIT to remove the units.