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.

Automate lookup table creation?

Evan_ReeseEvan_Reese Member Posts: 1,981 PRO
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.
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answers


  • Evan_ReeseEvan_Reese Member Posts: 1,981 PRO
    btw, I'm looking at these sets of functions and it feels like lookupTablePath() is supposed to do what I want. Am I close?
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Alex_KempenAlex_Kempen Member Posts: 244 EDU
    Answer ✓
    lookupTablePath 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:
    Sample usage is here:

    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 Dallas
    Check out my FeatureScripts here:

  • Evan_ReeseEvan_Reese Member Posts: 1,981 PRO
    Thanks, Alex. I may end up writing a function to just print it with the right formatting then.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Stormi_BackusStormi_Backus Member Posts: 38 PRO
    Answer ✓
    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!

Sign In or Register to comment.