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:

  1. /**Populate palette*/
  2. // call populatePalette("MyPalette","MyRGBTable")
  3. // Table is assumed to have 4-5 columns: ColorId, R, G, B [,A]; all values ranging as per the international standard 0-255
  4. string paletteName = param(1);
  5. string tableName = param(2);
  6.  
  7. Table tblSource = Table(tableName);
  8. treenode palette = Model.find("Tools/ColorPalettes/" + paletteName);
  9.  
  10. if( objectexists(tblSource) && objectexists(palette) ) {
  11. treenode colorNodes = getvarnode(palette, "colorNodes");
  12. colorNodes.subnodes.clear();
  13. for( int row = 1; row <= tblSource.numRows; row++ ) {
  14. treenode currentColor = colorNodes.subnodes.add();
  15. currentColor.value = tblSource[row][1];
  16. treenode r = currentColor.subnodes.add();
  17. treenode g = currentColor.subnodes.add();
  18. treenode b = currentColor.subnodes.add();
  19. treenode a = currentColor.subnodes.add();
  20. r.name = "r";
  21. g.name = "g";
  22. b.name = "b";
  23. a.name = "a";
  24. r.value = tblSource[row][2] / 255;
  25. g.value = tblSource[row][3] / 255;
  26. b.value = tblSource[row][4] / 255;
  27. if( tblSource.numCols > 4 ) {
  28. a.value = tblSource[row][5];
  29. } else {
  30. a.value = 1;
  31. };
  32. //a.value = (tblSource.numCols > 4 ? tblSource[row][5] : 1); // Returns "Invalid cast from int to TableElement" ?!?
  33. };
  34. };
5 |100000

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