Slicer 4.10.2 Model Imports

I’m trying to import stl files from my PC on Slicer 4.10.2 because I’m modifying an old module that doesn’t work on newer versions of Slicer. However, it seems like the code I normally use on Slicer 5.1.0 doesn’t work for this, and I was wondering what the correct commands are. Here is what I have:

    self.stylusModel = slicer.util.loadModel('C:/calibrationClarius/Current_Models/stylusV2')
    self.stylusModelDisplayNode = self.stylusModel.GetDisplayNode()
    self.stylusModelDisplayNode.SetColor(0, 0.5, 0.1)

And here is the error on the Slicer python console:

File "C:/calibrationClarius/leahCalibModified/Calibration/Calibration.py", line 47, in __init__
    self.stylusModelDisplayNode = self.stylusModel.GetDisplayNode()
AttributeError: 'bool' object has no attribute 'GetDisplayNode'

Furthermore, I was wondering where I could find an old Script repository for code that works on 4.10.2 I can refer to in the future. Thanks

In older versions of loadModel you needed to provide an extra boolean parameter returnNode=True as described here.

1 Like

I would recommend to update the module instead of downgrade Slicer. Check out the migration guide for description of API changes and how to update old code. You can ask on this forum if you cannot figure out how to update any specific part in your module.