ACT Python or JS: How to get the view objects (managed views) and get their names?
Am I missing something or are there still basic capabilities of accessing the views by scripting missing?
mvm = ExtAPI.Graphics.ModelViewManager
I can e. g. get the number of views by
mvm.NumberOfViews
but how to get the objects? And how to get their names?
A straight forward implementation would in my opinion allow something like
my_views = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.View)
for my_view in my_views:
print(my_view.name)
Answers
-
There might be a better way than this, but if you write out the views, you can read the xml file and get this information. E.g.:
def GetViews():
import xml.etree.ElementTree as ET
import wbjn
import os
UFD = wbjn.ExecuteCommand(ExtAPI,"returnValue(GetUserFilesDirectory())")
viewMgr=ExtAPI.Graphics.ModelViewManager
#Export and read xml to find names
xmlFile=os.path.join(UFD,"PicturesViews.xml")
viewMgr.ExportModelViews(xmlFile)
Doc = ET.parse(xmlFile)
Root = Doc.getroot()
viewMgrNames={}
for i,XmlNode in enumerate(list(Root)):
if XmlNode.tag=="ModelView":
viewMgrNames[XmlNode.attrib['Name']]=i
return viewMgrNamesApply a view by name to the selected tree object
treeObj = Tree.FirstActiveObject
viewName = 'View1'ViewNames = GetViews()
viewMgr = ExtAPI.Graphics.ModelViewManagerif viewName in ViewNames:
viewMgr.ApplyModelView(ViewNames[viewName])0 -
Thanks for your effort Eric. I will try out your workaround.
Although I still hope, that there is a simpler and shorter solution.
0