Set up different scene for Slicer

Hi. I want to create a new scene and set it up as principal scene that is because I want to populate a combobox with a list of models (the default scene has some models that I don’t want on the combobox)
This code creates a scene:

self.myscene = slicer.vtkMRMLScene()

but I don’t know how to select it, something like this:

slicer.utils.setMRMLScene(self.myscene)

Now load the list of models to myscene:

for mypath in listOfModelPaths:
    #add model to myscene
    newModel = slicer.modules.models.logic().AddModel(mypath)

Here I create and populate the combobox

self.inputComboBox = slicer.qMRMLNodeComboBox()
self.inputComboBox.nodeTypes = ['vtkMRMLModelNode']
self.inputComboBox.setMRMLScene(self.myscene)
self.__layout.addWidget(self.inputComboBox)

@lassoan Could you help with this?

There is just one scene that the application knows about. You can create a new scene object but it will not contain any of your nodes (a node can only be in one scene).

If you want to show only certain models then you can add a custom attribute to your nodes and use that for filtering - see http://apidocs.slicer.org/master/classqMRMLNodeComboBox.html#a056b54be78c6053b6fd21d51b2b1d045

Yes Andras. Thank you for the help. I had found that function in the documentation but I didn’t understand how to use it with vtkMRMLModelNode. I don’t know with what to replace “Category” and “Discrete”. I would like to show only some models I select. For example: show only models that start with “MyModelType1” and “MyModelType2”
So in this list:
MyModelType1D is shown
MyModelType1G is shown
MyModelType2H is shown
MyModelType2J is shown
MyModelType3R isn’t shown
MyModelType3Y isn’t shown

You can choose any text as attribute name and you can filter for value or presence of that attribute. For example:

someNode.SetAttribute('MySpecialNodeCategory', '1')
comboBox.addAttribute('vtkMRMLModelNode', 'MySpecialNodeCategory', '1')
1 Like