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.

Options

Automate lookup table creation?

Evan_ReeseEvan_Reese Member Posts: 2,068 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

Answers

  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,068 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
  • Options
    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:
    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 Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,068 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
  • Options
    Stormi_BackusStormi_Backus Member Posts: 49
    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!

    https://cad.onshape.com/documents/451d03e40b1de718b2c4a8b3/w/4a2c50a4de51d485cccf68c8/e/ad42f666ef71bcf127f0691c
Sign In or Register to comment.