question

Gui Vaccaro avatar image
0 Likes"
Gui Vaccaro asked Gui Vaccaro answered

Import color palette from table

Hello,
what is the column format to import the colors from a table to a palette using the option "Auto-fill from Global table"? The first column has the color names. The following columns have the color specification. I tried R, G, B (3 columns), RGB (as a bundle in a single column), HEX, ... so far, without success. Also, where is this information in the documentation, please?
Thank you for the clarification.

FlexSim 25.0.0
tableimportpalete
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Gui Vaccaro avatar image
0 Likes"
Gui Vaccaro answered

This is my solution (user command). This could be an addition to FlexSim:

/**Populate palette*/
// call populatePalette("MyPalette","MyRGBTable")
// Table is assumed to have 4-5 columns: ColorId, R, G, B [,A]; all values ranging as per the international standard 0-255
string paletteName = param(1);
string tableName = param(2);

Table tblSource = Table(tableName);
treenode palette = Model.find("Tools/ColorPalettes/" + paletteName);

if( objectexists(tblSource) && objectexists(palette) ) {
treenode colorNodes = getvarnode(palette, "colorNodes");
colorNodes.subnodes.clear();
for( int row = 1; row <= tblSource.numRows; row++ ) {
treenode currentColor = colorNodes.subnodes.add();
currentColor.value = tblSource[row][1];
treenode r = currentColor.subnodes.add();
treenode g = currentColor.subnodes.add();
treenode b = currentColor.subnodes.add();
treenode a = currentColor.subnodes.add();
r.name = "r";
g.name = "g";
b.name = "b";
a.name = "a";
r.value = tblSource[row][2] / 255;
g.value = tblSource[row][3] / 255;
b.value = tblSource[row][4] / 255;
if( tblSource.numCols > 4 ) {
a.value = tblSource[row][5];
} else {
a.value = 1;
};
//a.value = (tblSource.numCols > 4 ? tblSource[row][5] : 1); // Returns "Invalid cast from int to TableElement" ?!?
};
};
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.