ACT Python or JS: How to get the view objects (managed views) and get their names?

Matthias
Matthias Member Posts: 10
Name Dropper First Anniversary First Comment
**

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

  • Eric Stamper
    Eric Stamper Member, Employee Posts: 6
    Second Anniversary Ansys Employee First Comment Photogenic
    ✭✭✭
    edited November 18

    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 viewMgrNames

    Apply a view by name to the selected tree object

    treeObj = Tree.FirstActiveObject
    viewName = 'View1'

    ViewNames = GetViews()
    viewMgr = ExtAPI.Graphics.ModelViewManager

    if viewName in ViewNames:
    viewMgr.ApplyModelView(ViewNames[viewName])

  • Matthias
    Matthias Member Posts: 10
    Name Dropper First Anniversary First Comment
    **

    Thanks for your effort Eric. I will try out your workaround.

    Although I still hope, that there is a simpler and shorter solution.