Hi,
I noticed that if I try to programmatically create new folder in subject hierarchy and add there a node an error message is sent. Though the node is added to the folder.
The error message:
GetChildByPositionUnderParent: Failed to find subject hierarchy item under parent Scene at position 2
Here are the steps to reproduce:
- open the data module (so the subject hierarchy treeview gets initialized);
- copy/paste the code below (it creates model node, folder and adds the node to the folder):
# Create and set up polydata source
box = vtk.vtkCubeSource()
box.SetXLength(30)
box.SetYLength(20)
box.SetZLength(15)
box.SetCenter(10,20,5)
# Create a model node that displays output of the source
boxNode = slicer.modules.models.logic().AddModel(box.GetOutputPort())
# Adjust display properties
boxNode.GetDisplayNode().SetColor(1,0,0)
boxNode.GetDisplayNode().SetOpacity(0.8)
#-----------------------------------------
# Subject hierarchy part starts
#-----------------------------------------
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
folderID = shNode.CreateFolderItem(shNode.GetSceneItemID(), 'MyFolder')
# On this last step check the log, an error should appear there
shNode.CreateItem(folderID, boxNode)
By the way there is no such error when I use GUI to create folder and drag/drop the node to the folder.
Tested on Ubuntu 20.04 with Slicer dowloaded from official site 4.13.0-2022-02-02