Is there any way to create a model with several components in CLI

Is there any way to create a model with several components, and each component (a mesh model) with different color in CLI. Then, output the model and automatic loaded by Slicer.
Thanks!

Yes, you can look at the ModelMaker module. It’s slightly legacy at this point since we move to the Segmentation infrastructure but it still works to convert labelmaps to multiple colored models (meshes).

Thanks Steve! It’s a good suggestion. I developed a CLI using python, Slicer can be imported, but its modules cannot be found. Is it possible to save the model with color into a single vtk file and loaded it in Slicer? I had tried but the model can be loaded without color information.

You can make a single VTK polydata file with scalar colors but they won’t be turned on by default (user would need to turn them on in the Models module). The way the ModelMaker works is by writing out a mini-mrml scene that includes the color information for each polydata. The CLI infrastructure is intended to make it easy to do simple things, but if you need to do something more complex you might want to put the implementation in a module logic instead so you can use the full Slicer API.

Did you mean that if I want to use the full SlicerAPI, I should implement the module as a loadable module or scripted module rather than a CLI?

Yes, that’s right. CLI modules are a special case.