# Changing Model Color and Opacity in a Model with Multiple vtk Sources

**URL:** <https://discourse.slicer.org/t/changing-model-color-and-opacity-in-a-model-with-multiple-vtk-sources/30411>\
**Category:** Support\
**Tags:** 3d-model\
**Created:** [July 5, 2023, 3:12pm UTC](https://discourse.slicer.org/t/changing-model-color-and-opacity-in-a-model-with-multiple-vtk-sources/30411 "2023-07-05T15:12:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [July 5, 2023, 3:12pm UTC](https://discourse.slicer.org/t/changing-model-color-and-opacity-in-a-model-with-multiple-vtk-sources/30411/1 "2023-07-05T15:12:07Z")

</div>

I am trying to create models that have multiple distinct components using vtk’s appendFilter (shown in the example below). I would like to adjust the opacity and color of the different components separately. As a start, I tried to follow [this example](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#select-cells-of-a-model-using-markups-point-list) but was unable to change any colors this way. Any help would be greatly appreciated–thanks!

```auto
    # Component 1
    source1 = vtk.vtkCubeSource()
    source1.SetXLength(10)
    source1.SetYLength(10)
    source1.SetZLength(10)
    source1.SetCenter(0,0,-5)
    source1.Update()

    input1 = vtk.vtkPolyData()
    input1.ShallowCopy(source1.GetOutput())

    # Component 2
    source2 = vtk.vtkCubeSource()
    source2.SetXLength(10)
    source2.SetYLength(10)
    source2.SetZLength(10)
    source2.SetCenter(0,0,5)
    source2.Update()

    input2 = vtk.vtkPolyData()
    input2.ShallowCopy(source2.GetOutput())

    # AppendFilter -> Model
    appendFilter.AddInputData(input1)
    appendFilter.AddInputData(input2)
    appendFilter.Update()
    model= slicer.modules.models.logic().AddModel(appendFilter.GetOutput())

    # Something like this to change the model components' colors, though I'd like to change their colors separately
    colorArray = vtk.vtkUnsignedCharArray() # Set color scalars
    colorArray.SetName("color")
    nCells = appendFilter.GetOutput().GetNumberOfCells()
    colorArray.SetNumberOfTuples(nCells)
    for i in range(nCells):
        colorArray.InsertTuple3(i, 255, 0, 0)
    model.GetDisplayNode().SetActiveScalar("color", vtk.vtkAssignAttribute.CELL_DATA)
    model.GetDisplayNode().SetAndObserveColorNodeID("vtkMRMLColorTableNodeWarm1")
    model.GetDisplayNode().SetScalarVisibility(True)

```
