Get Selected ICE Compound function


Needed to get the selected ICE Compounds via scripting today and finally got a working function that returns a dictionary { Name:FullName }. See below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from win32com.client import constants as c
 
xsi = Application
log = xsi.LogMessage
 
def getSelectedICECompounds():
collViews = xsi.Desktop.ActiveLayout.Views
oICETreeView = collViews("ICE Tree")
 
if oICETreeView:
strNodes = oICETreeView.GetAttributeValue("selection")
 
if not strNodes:
log("No nodes selected.")
return
 
lSelectedNodes = strNodes.split(",")
dICECompounds = {}
for eachNode in lSelectedNodes:
oNode = xsi.Dictionary.GetObject(eachNode)
 
if oNode.IsClassOf(c.siICECompoundNodeID):
lFullNameSplit = oNode.FullName.rsplit(".")
dICECompounds[lFullNameSplit[len(lFullNameSplit) - 1]] = oNode.FullName
 
return dICECompounds
 
else:
log("ICE Tree view not found!",2)