Table Creation

Hello all,

I’m trying to create a Table, and in the Documents is written that a User can create rows, but when I’m in the editor there is not an ‘+’ sign as when I create a DynamicArray. Do I have to create all the rows first? If yes, I tried adding a default value based on a list, but I get the error: Object of type function is not JSON serializable. Here is a code snippet:

def node_list(params):
    if params.geometry.truss_type == 'Warren' and params.geometry.truss_style == 'Without Vertical Elements':
        return [{'node_id':i,'fx':0,'fy':0} for i in range(1,(params.geometry.divisions*2)+2)]

class Parametrization(ViktorParametrization):
    geometry.divisions = NumberField('Number of Truss Spans:', min=2, max=20, num_decimals=0, variant='slider', default=5)
    tab3 = Tab('Loads & Supports')
    tab3.noad_load_table_button = BooleanField('Node Load Table',default=False)
    tab3.noad_load_table = Table('Node Load Table',visible=IsNotEqual(Lookup('tab3.noad_load_table_button'),False),

PS: when I put a list of dicts that follow the same pattern generated by the function node_list it works perfectly.

Hi there,

Okay the problem here is two-fold: on the one hand you’re struggling with how the user should create new rows in a table and on the other you’re trying to implement a default table which isn’t working.

The creation (and deletion) of new rows in a table is most easily done by simply right-clicking the table and choosing the three options (“add new row above”, “add new row below” or “remove row”). You are correct that the table does not include a button to add new rows. This is a design choice to keep the table field somewhat more compact than the DynamicArray.

The creation of a default table as you present it in your snippet is an example of trying to implement “dynamic defaults”. This topic is discussed on this forum multiple times (see Function lookup - set default values optionfield or Change table content when changing dropdown menu selection or Questions on OptionField and accessing Table column data for example) but the short story is that it is currently not possible. The reason that a simple dict of values does work in your case is that by doing that you’re not depending on other params to constitute that default table.

Does that clarify some things for you?
Please let me know if you have more questions!

Hello Daniel,

Thanks for the fast reply, as you told there is a lot of topics with this subject. With right-click solves all my issues, but I didn’t think about it at first hahaha :sweat_smile: .

1 Like

Well this is what the community forum is for :wink:

Happy coding!!

1 Like