Re: Diving into python, some questions...

Date : Thu, 24 Aug 2006 00:07:04 -0700
To : XSI(at)Softimage.COM
From : "Steven Caron" <carons(at)gmail.com>
Subject : Re: Diving into python, some questions...
thanks for that Nick

at that point when i posted the code it was giving me syntax errors, and i hadnt run into some of the other problems.
your suggestions do make it faster, and the code simpler... they were not kidding in the books when they suggested its simpler shorter to code

good stuff though, thanks for taking the time to share!

Steven

On 8/23/06, Nick <nick.petit(at)gmail.com > wrote:
Pythin allows you to enumerate through lists, collections, a bit like in VB with the "for each ... in ..." which allows you to get to the individual items a lot quicker...


import xml.dom.minidom

#assign Application to a smaller variable
app = Application

#get the all the passes in the scene
oPasses = app.ActiveProject.ActiveScene
.Passes

#new XML doc
doc = xml.dom.minidom.Document()

#root element
passList = doc.createElement("PassList")
doc.appendChild(passList)

#pass elements
for oPass in oPasses:  # get each pass directly, its faster and you get to the objects you want quicker...
    passElem = doc.createElement (oPass.Name)

    passList.appendChild(passElem)
   
    #render options for each pass
    rOptElem = doc.createElement("RenderOptions")
    #rOptions = oPass.NestedObjects(3).Parameters   I'm still on 4.2 so I don't have access to "NestedObjects", so I use this instead :
    rOptions = app.EnumElements(oPass)(3).Parameters

   
    #render option's parameters and values
    for oParam in rOptions: #first syntax error
        # if rOptions.Value:  Here, you're trying to get to the value of a Collection, not an individual Parameter...
        if oParam.Value:
            parElem = doc.createElement(oParam.Name)
            rOptElem.appendChild (parElem)
            parTxt = doc.createTextNode(oParam.Value)
            parElem.appendChild(parTxt)
  ...

Hopefully that gets you on your way, I can't go on too much further as I'm missing "NestedObjects"



Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.