Diving into python, some questions...

Date : Wed, 23 Aug 2006 23:03:28 -0700
To : xsi(at)Softimage.COM
From : "Steven Caron" <carons(at)gmail.com>
Subject : Diving into python, some questions...
hey
i thought getting into python would be easier or at least more fun... I am not having much fun at the moment, maybe someone can share some insight.

I have read about the collection types in python. lists, dictionaries, tuples great stuff. but in XSI i have noticed that sometimes i can use [ ] brackets when indexing an XSICollection and I can also use ( ) as normal. i shouldn't do that right?

Does the extra collection types in python interfere with XSICollections?
When a method returns an XSICollection is python interpreting that some other way, maybe into its native collection types?

also i am getting syntax errors on loops that look exactly like other loops a few lines up... after i couldn't figure out what the syntax problem was, i just removed the whole loop. then the loop above that threw an error. then after removing all of the loops, stuff that was working only mins before starts throwing syntax errors. confusing and frustrating

so here is where my code stands now... if some python guru wouldn't mind pointing out something so close it could bite me

#start code

'''
playing with python and xml
'''

#lets import the xmldom module
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 i in range(oPasses.Count):
    passElem = doc.createElement (oPasses(i).Name)
    passList.appendChild(passElem)
   
    #render options for each pass
    rOptElem = doc.createElement("RenderOptions")
    rOptions = oPasses(i).NestedObjects(3).Parameters
   
    #render option's parameters and values
    for j in range(rOptions.Count): #first syntax error
        if rOptions.Value:
            parElem = doc.createElement(rOptions(j).Name)
            rOptElem.appendChild (parElem)
            parTxt = doc.createTextNode(rOptions(j).Value)
            parElem.appendChild(parTxt)
       
    #partitions for each pass
    partColl = oPasses(i).NestedObjects(0).NestedObjects #after removing the loop above this, this starts to thow errors :(
    for h in range(partColl.Count):
        partElem = doc.createElement(partColl(h).Name)
        passElem.appendChild(partElem)
       
        #memberships
        memberElem = doc.createElement("Memberships")
        partElem.appendChild(memberElem)
        members = partColl(h).Members.GetAsText()
        memberTxt = doc.createTextNode(members)
        memberElem.appendChild(memberTxt)

#write doc
fileName = "c:/pass.xml"
try:
   # Open a file stream in write mode
   output = open(fileName, 'w')
   output.write(doc.toprettyxml())

except OSError, e:
   print "Could not write XML file!"

#end code

thanks!
Steven

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.