Hi all,
I’m experimenting with an Dynamic Array in which an user can select a certain material, colour and finish. The combination of these three inputs returns a set of variables required for further calculations.
To streamline this array I want to enable only the options that work for that given material. I want to do this based on information stored in a Pandas DataFrame. The reason for this workflow is rather simple as Material A has colour X, Y and Z, while Material B only has X, Y and another colour named D. I use the same logic for the finish column.
Now I’m using the following code, yet I cannot use the value under ‘Material’ for my pandas selection statement. Currently all possible options for colour and finish are shown, meaning for material A, B and C combined.
This is my code:
with df_path.open() as f:
df= pd.read_csv(df_path)
class Parametrization(ViktorParametrization):
array= DynamicArray("Material properties")
array.name= TextField("Element name")
array.material = OptionField(
"Material",
options=list(df.loc[:,'Material'].unique()),
default=list(df.loc[:,'Material'].unique())[0]
)
array.colour= OptionField(
"Colour",
options=list(df[df['Material'] == array.colour].loc[:,'Colour'].unique())
)
array.finish= OptionField(
"Finish",
options=list(df[(df['Material'] == array.material) & (df['Colour'] == array.colour)].loc[:,'Finish'].unique())
)
I already tested the following methods: OptionListElement and a function to get the right options (User input, fields and buttons - Options & selections | VIKTOR Documentation). Both don’t work for a DynamicArray.