# Problem in render a volume on import

**URL:** https://discourse.slicer.org/t/problem-in-render-a-volume-on-import/34428
**Category:** Support
**Created:** [February 20, 2024, 4:03pm UTC](https://discourse.slicer.org/t/problem-in-render-a-volume-on-import/34428 "2024-02-20T16:03:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![calvinsuzuki](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/calvinsuzuki/32/69398_2.png) [@calvinsuzuki](https://discourse.slicer.org/u/calvinsuzuki)
#### Post date: [February 20, 2024, 4:03pm UTC](https://discourse.slicer.org/t/problem-in-render-a-volume-on-import/34428/1 "2024-02-20T16:03:01Z")

</div>

Hey guys, I’ve been trying to do a very simple task on Slicer.

Just to display the rendered model on drag n drop import.

It rarely works, but in most cases I got the error:

Warning: In /work/Stable/Slicer-0/Modules/Loadable/VolumeRendering/Logic/vtkSlicerVolumeRenderingLogic.cxx, line 674  
vtkSlicerVolumeRenderingLogic (0x7825480): CopyDisplayToVolumeRenderingDisplayNode: No display node to copy.

I used this on start of my module: [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#show-volume-rendering-automatically-when-a-volume-is-loaded)

[image deleted per request]

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [February 20, 2024, 4:07pm UTC](https://discourse.slicer.org/t/problem-in-render-a-volume-on-import/34428/2 "2024-02-20T16:07:02Z")

</div>

There have been some recent improvements in volume rendering initilization. Please try with the latest Slicer Preview Release and let us know it the issue persists.

---

<div class="post-metadata">

### Author: ![calvinsuzuki](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/calvinsuzuki/32/69398_2.png) [@calvinsuzuki](https://discourse.slicer.org/u/calvinsuzuki)
#### Post date: [February 23, 2024, 4:00pm UTC](https://discourse.slicer.org/t/problem-in-render-a-volume-on-import/34428/3 "2024-02-23T16:00:47Z")

</div>

Hello Andras! Thanks for reaching out!  
I’m currently using the 5.2.2 version, I’ve managed to solve this issue by raising the time value of `qt.QTimer.singleShot` then dinamically checking if it was loaded and increasing the load time using `volRenLogic.SetRecommendedVolumeRenderingProperties(displayNode)`

```auto
    def showVolumeRendering(self, volumeNode):
        volRenLogic = slicer.modules.volumerendering.logic()

        # Check if node exists, if not create a new one
        displayNode = slicer.mrmlScene.GetFirstNodeByName('VolumeRendering')
        if displayNode is None:
            displayNode = volRenLogic.CreateVolumeRenderingDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)

        # Set recommended volume rendering properties will return False if the
        if not volRenLogic.SetRecommendedVolumeRenderingProperties(displayNode):
            # If already using the largest loading time, print error message and return
            if len(self.loading_time) == 1:
                print('Failed to load volume! Please, drag it manually from Data.')
                return
            # If not, increase the loading time and try again 
            else:
                self.loading_time.pop(0)
                print('Failed to load volume! Increasing loading to ' + str(self.loading_time[0]) + 'ms.')
                qt.QTimer.singleShot(self.loading_time[0], lambda: self.showVolumeRendering(volumeNode))

        # ensure the display node is visible
        displayNode.SetVisibility(True)

        # add the volume to the display node
        volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())
        volRenLogic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)

        # update the preset based on the volume scalar range
        scalarRange = volumeNode.GetImageData().GetScalarRange()
        if scalarRange[1]-scalarRange[0] < 1500:
            # Small dynamic range, probably MRI
            displayNode.GetVolumePropertyNode().Copy(volRenLogic.GetPresetByName("MR-Default"))
        else:
            # Larger dynamic range, probably CT
            displayNode.GetVolumePropertyNode().Copy(volRenLogic.GetPresetByName("CT-Chest-Contrast-Enhanced"))

```
