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.
Automate lookup table creation?
EvanReese
Member, Mentor Posts: 2,144 ✭✭✭✭✭
I want to make a function to generate a lookup table map with FS. My function creates the right map (I think), but I can't add it to a feature precondition; it says its not a "map literal". Is that because of regeneration order making the precondition run before the function? If so, how should I go about generating a lookup table with FS instead of typing it manually?
I considered just printing it all to the notices panel to copy/paste, but it loses some important formatting, which I don't want to edit. I could brute force it with a function that concatenates stuff just to print it with the right formatting, but it doesn't feel like The Right Way.
I considered just printing it all to the notices panel to copy/paste, but it loses some important formatting, which I don't want to edit. I could brute force it with a function that concatenates stuff just to print it with the right formatting, but it doesn't feel like The Right Way.
Evan Reese
0
Best Answers
-
Alex_Kempen Member Posts: 248 EDUlookupTablePath is a function for getting a given value of a lookup table from a lookup table parameter. Without it, a lookup table parameter (e.g. definition.myLookupTable) is just a map containing the key value pairs of selections the user has made into the table, which isn't terribly helpful. There should be an example of that in the docs.In regards to your original question, lookup tables, like all UI elements in FeatureScript, must be specified statically - that is, they must be physically typed out in code before you hit commit. Because of that, there's no way to write a FeatureScript function to generate UI values like enums or lookup tables at runtime. So unfortunately, the only thing you really can do is print it to the console and then copy and paste it into a FeatureStudio manually.It sounds like you have this mostly working already, but if you're interested, I also have an old studio I wrote a while ago for generating lookup tables here:https://cad.onshape.com/documents/00dd11dabe44da2db458f898/w/6c20cd994b174cc99668701f/e/31260530220599ab32f16907
Sample usage is here:
https://cad.onshape.com/documents/00dd11dabe44da2db458f898/w/6c20cd994b174cc99668701f/e/f163540c795292bba4e35039
I'm also currently working on porting it over to Python as a part of some of my other FeatureScript code generation shenanigans, but you probably don't need something that industrial for your purposes.
CS Student at UT DallasAlex.Kempen@utdallas.eduCheck out my FeatureScripts here:1 -
Stormi_Backus Member Posts: 49 ✭Hey Evan,
Jacob Corder got bored and made me this example recently...I haven't used it yet so I can't answer any questions but the meat and potatoes of it all is in the "CSV to lookup table" tab on this document. Disregarding all my McGuire sprocket nonsense, maybe this will help!
https://cad.onshape.com/documents/451d03e40b1de718b2c4a8b3/w/4a2c50a4de51d485cccf68c8/e/ad42f666ef71bcf127f0691c
1
Answers
Sample usage is here:
https://cad.onshape.com/documents/00dd11dabe44da2db458f898/w/6c20cd994b174cc99668701f/e/f163540c795292bba4e35039
I'm also currently working on porting it over to Python as a part of some of my other FeatureScript code generation shenanigans, but you probably don't need something that industrial for your purposes.
Jacob Corder got bored and made me this example recently...I haven't used it yet so I can't answer any questions but the meat and potatoes of it all is in the "CSV to lookup table" tab on this document. Disregarding all my McGuire sprocket nonsense, maybe this will help!
https://cad.onshape.com/documents/451d03e40b1de718b2c4a8b3/w/4a2c50a4de51d485cccf68c8/e/ad42f666ef71bcf127f0691c