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.

Convert column in imported CSV to a user selectable list

shawn_crockershawn_crocker Member, OS Professional Posts: 798 PRO
Title says it all.  Just can't figure out how this is done. CUSTOM SHEET METAL FEATURES | sheetMetalStart.fs Copy 1 (onshape.com)

Thanks so much if you can provide an example or point to one.
Tagged:

Best Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Answer ✓
    Sorry to lead you astray there @Alex_Kempen but all user interface components must be static so nothing can be done on the fly. 

    What I was referring to was some sort of external parsing code that could convert csv into a map suitable for a LookUpTable. You would then have to copy/paste the resulting text into a separate Feature Studio and reference that in your feature. So if the csv changes you would have to update your feature each time. 


    Senior Director, Technical Services, EMEAI
  • shawn_crockershawn_crocker Member, OS Professional Posts: 798 PRO
    Answer ✓
    NeilCooke said:
    Sorry to lead you astray there @Alex_Kempen but all user interface components must be static so nothing can be done on the fly. 

    What I was referring to was some sort of external parsing code that could convert csv into a map suitable for a LookUpTable. You would then have to copy/paste the resulting text into a separate Feature Studio and reference that in your feature. So if the csv changes you would have to update your feature each time. 


    So your saying I can do the processing of the csv in a feature studio to create a map for export and then import that map into my feature to use as the lookup table reference?  Or are you saying no matter what, the map for the lookup table has to be literally written out either in a separate studio or directly in the actual features studio?  If the latter is so, anyone know why the limitation exists?  It would be so useful to be able to generate a list by simply update a csv or selecting one using a csv input parameter.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Answer ✓
    yeah the second one unfortunately. 
    Senior Director, Technical Services, EMEAI

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    This is not possible because enum lists are static. The only way to do this would be to create a lookupTable. 
    Senior Director, Technical Services, EMEAI
  • Alex_KempenAlex_Kempen Member Posts: 244 EDU
    The easiest alternative is probably to break out your UI and values into a separate, easily modifiable Feature Studio. I did that for my Variable Library FS, which you can find here. Some creatively nested maps, comments, and the relevant enum makes it fairly easy for users to copy and add their own functions as they desire - they just have to update the relevant import in the top of the Variable Library feature studio first.
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • shawn_crockershawn_crocker Member, OS Professional Posts: 798 PRO
    @Alex_Kempen
    Thanks.  I will have to do some experimenting with reusing existing code and just creating a new interface.  For the time being, I have just created an enum that matches the values in the csv.  It works OK for me but my secondary goal is to have a feature that other people can use without having to dig into the code to use.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 798 PRO
    @NeilCooke
    2.5 years later and I am finally revisiting this.  :D .  Are you able to clarify how a .csv can be used to populate a lookup table?  I have been messing around a bit and it feels like featurescript really wants me to define the const explicitly.  I have tried sneaking in a function to create a const that includes a loop to format the cvs data in the way the lookup needs it to be structure.  Featurescript still seems to be able to tell I'm trying to pull a fast one on it.

    FeatureScript 2180;
    import(path : "onshape/std/common.fs", version : "2180.0");
    
    tableImport :: import(path : "f0d380b93788decd49c82f69", version : "eee16caca18b5c1eee402ab8");
    const tablePlot = tableImport::BLOB_DATA.csvData;
    
    function test(x) {
        var z = {};
        z[x] = {"name" : x};
        return z;
    }
    const test2 = test(tablePlot[0]);
    
    export const sizeTable = {
        "name" : "region",
        "displayName" : "Region",
        "entries" : test2,
    };
    
    annotation { "Feature Type Name" : "My Feature" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Soda size", "Lookup Table" : sizeTable }
            definition.size is LookupTablePath;
        }
        {
            
        });
    

    The error looks like this:



    Any guidance on this would be great.  Being able to reference a csv to drive a list of options would greatly streamline some features I have cobbled together.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Answer ✓
    Sorry to lead you astray there @Alex_Kempen but all user interface components must be static so nothing can be done on the fly. 

    What I was referring to was some sort of external parsing code that could convert csv into a map suitable for a LookUpTable. You would then have to copy/paste the resulting text into a separate Feature Studio and reference that in your feature. So if the csv changes you would have to update your feature each time. 


    Senior Director, Technical Services, EMEAI
  • Konst_ShKonst_Sh Member Posts: 36 PRO
    You can dynamically convert csv table into array parameter, and handle this array generation in editing logic function. To select the concrete entry you will need to add some boolean flag to array items that when when you set certain item as selected will be unchecked for all other items.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 798 PRO
    Answer ✓
    NeilCooke said:
    Sorry to lead you astray there @Alex_Kempen but all user interface components must be static so nothing can be done on the fly. 

    What I was referring to was some sort of external parsing code that could convert csv into a map suitable for a LookUpTable. You would then have to copy/paste the resulting text into a separate Feature Studio and reference that in your feature. So if the csv changes you would have to update your feature each time. 


    So your saying I can do the processing of the csv in a feature studio to create a map for export and then import that map into my feature to use as the lookup table reference?  Or are you saying no matter what, the map for the lookup table has to be literally written out either in a separate studio or directly in the actual features studio?  If the latter is so, anyone know why the limitation exists?  It would be so useful to be able to generate a list by simply update a csv or selecting one using a csv input parameter.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Answer ✓
    yeah the second one unfortunately. 
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.