Copy model display node

I have a generated a new model derived from a source model. I want the new display properties (including selected scalars) of the target model to be the same as the source model. I tried various Copy functions with no success.

modelDisplayNode = modelNode.GetDisplayNode()
    
newModel1 = slicer.vtkMRMLModelNode()
newModel1.SetAndObservePolyData(surfaceFilter1.GetOutput())

newDisplayNode1 = slicer.vtkMRMLModelDisplayNode()
newDisplayNode1.CopyWithScene(modelDisplayNode)
slicer.mrmlScene.AddNode(newDisplayNode1)
    
newModel1.SetAndObserveDisplayNodeID(newDisplayNode1.GetID())
slicer.mrmlScene.AddNode(newModel1)

Simple Copy of the display node should work:

newModel1 = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode')
newModel1.SetAndObservePolyData(surfaceFilter1.GetOutput()))
newModel1.CreateDefaultDisplayNodes()
newModel1.GetDisplayNode().Copy(modelNode.GetDisplayNode())

A more generic option is to use Subject Hierarchy module’s clone function, which can clone any node. See this example.

1 Like