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.

Default value for a lookupTablePath?

dave_cowdendave_cowden Member, Developers Posts: 445 ✭✭✭
How do you set the default value for a lookup table path? 

When i set up a lookupTable path variable, i expect the default value to be the one selected via the 'default'
clause in the lookup table itself.

But what i find is that the value is empty until the user chooses a value from it, at which point, it is populated.

What is the right way to ensure that the initial value of a lookupPath definition field is set to the default values initially displayed?

Best Answer

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 943
    I'm not seeing that -- when I type the following, I get a correct default.
    const lookupTable = {
            "name" : "choice1",
            "displayName" : "First Choice",
            "default" : "y",
            "entries" : { "x" : "1", "y" : "2", "z" : "3" }
        };
    
    annotation { "Feature Type Name" : "My Feature" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Lookup table" : lookupTable }
            definition.p is LookupTablePath;
        }
        {
            // Define the function's action
        }, { /* default parameters */ });
    

    If you can post a small code snippet where this is breaking here, I'll log a bug.
    Ilya Baran \ Director, Architecture and FeatureScript \ Onshape Inc
  • dave_cowdendave_cowden Member, Developers Posts: 445 ✭✭✭
    weird. so with that sample, inside of an editing logic function, and inside of the body,

    print( definition.p ) would give { "choice1" : 'y' } ?

    for me in both cases, and before any user click, definition.p would be an empty set. I'll make see if i can make a simple document to repro-- may example is way too complex to post, so it coudl have a bug too.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 943
    Ah, no -- I was just looking at the UI.  Logging a bug.
    Ilya Baran \ Director, Architecture and FeatureScript \ Onshape Inc
  • dave_cowdendave_cowden Member, Developers Posts: 445 ✭✭✭
    Ok. as a side note, the hole feature in std. works around this-- somehow. The code was a bit too complex, i gave up trying to figure it out.

    In my case, for now the workaround was to do something like this in the editingLogicFuntion:

    var lookupPath = definition.path
    if ( oldDefinition == {} ){
        lookupPath = lookupPath ( { 'choice': 'p' } )
    }

    this allowed me to continue as if it was populated as I expected. but of course this code is brittle because it is a duplicate of what's already in the lookup table.
Sign In or Register to comment.