Getting a ref model's target file in python

Publié le par Ahmidou

It was not so easy so here it is:

from win32com.client import constants
xsi = Application
oRoot = xsi.ActiveSceneRoot
oModels = oRoot.getmodels2()
for oModel in oModels:
    if oModel.parameters("referenced_model").GetValue2(1280) == 1:
        aRes =oModel.parameters("active_resolution").GetValue2(1280)
        oParams = oModel.NestedObjects
        for oItem in oParams:    
            if == "Resolutions":
                oFile = (oItem.NestedObjects[aRes].NestedObjects[0].GetValue2(1280))
                xsi.logmessage (oFile)

Commenter cet article

Alan Fregtman 27/10/2011 20:03

# Your code ignores refmodels not in the scene root, and it can be even simpler:

xsi = Application
oRoot = xsi.ActiveSceneRoot

oModels = oRoot.FindChildren2("*", "modelnull", "Nulls", True)
oModels = filter(lambda x: x.referenced_model.Value, oModels)

for oModel in oModels:
aRes = oModel.Parameters("active_resolution").Value
res = oModel.NestedObjects("Resolutions").NestedObjects

resName = res(aRes).NestedObjects("Name").Value
resPath = res(aRes).NestedObjects("file").Value


# ;)