Change models color

Hello! I’m trying to take my first steps in developing extensions for 3D slicer.
I want to make an extension that changes the color of a model:

model_name = "ModelName"
node_model = getNode(model_name)
node_model.GetDisplayNode().SetColor(1, 0, 0)

This works fine to change the color but the color is not changed in the 3D view or in the cuts.

Should the scene be updated after changing a parameter?

Where do you see the color change?

By default, when you load a model a display node is automatically added. Have you added an additional display node for the model?

How many models do you have in the scene? Is it possible that you have loaded the same model multiple times and the one that you are changing is occluded by the others?

The change takes effect immediately. No manual updates are needed after changing properties of the display node.

Thank you for your response.
I see the color change in the models module but it does not change in the 3D view.

If I manually change the color from the models module, then the changes I make to the color from the Python interactor take effect. It would seem that there is something in the initial color configuration. The model is a VTK file of a tract that is initially loaded with the color I show in the image.






Hello, I think I found the problem. The models are built from .trk files and have the Scalars visibility option active. After the instruction mi_node.GetDisplayNode().SetScalarVisibility(False) I can change the color of the models.

1 Like