Hello all,
I am having some trouble with my recursive function, I have written a few
for this project and have not seen this behaviour until now.
It is looping over certain xml elements in a file and looking for the
correct one based on your selected QTreeWidgetItem which is working fine up
to a certain recursion level, I have jumped into the debugger a few times
and cannot wrap my head around whats going on.
My issue is when you hit a deeper recursion level as I hit the correct item
(if item == treeviewitem[0]) it jumps in and gets the correct XML element
which is exactly what I need EXCEPT when it returns it returns to the very
bottom gatherXMLElementInfo line and repeats the process even though the
process is complete and I dont need it to anymore and is causing program
errors.
I was under the assumption that once the function is complete and something
is returned the program should finish iterating through the code, it has
been this way so far so I am wondering if I am missing something??
Function is below :)
Thanks for the help!
def gatherXMLElementInfo(treeViewItems, root):
#print root.attrib
# Iterate backwards through the object list
for item in reversed(treeViewItems):
# If the current item is the last item in the list
if item == treeViewItems[0]:
#print "Item is", item
# We need to iterate through the parent element
children i.e. the list that our element is hiding in
if not item in self.elemsToIgnore:
if root.getchildren():
for elem in root.getchildren():
elemAttributes = elem.attrib
correctElement =
[elemAttributes.get(i) for i in elemAttributes if elemAttributes.get(i) == item]
if correctElement:
print correctElement[0]
break
return
else:
return
else:
if item in self.elemsToIgnore:
print "IGNORE", item
xmlElem = root.findall(item)[0]
else:
################# Fix this loop! #############
# Need to get the element from the name of the
qt displayed item
for child in root.getchildren():
#print child, root
elemAttributes = child.attrib
correctElement = [elemAttributes.get(i)
for i in elemAttributes if elemAttributes.get(i) == item]
if correctElement:
print "FOUNDDDDDD IT", child
xmlElem = child
break
listMinusOne = [i for i in treeViewItems if not i ==
item]
print " XML ELm", xmlElem
gatherXMLElementInfo(listMinusOne, xmlElem)
print "IGNORE", item
xmlElem = root.findall(item)[0]
else:
################# Fix this loop! #############
# Need to get the element from the name of the qt displayed item
for child in root.getchildren():
#print child, root
elemAttributes = child.attrib
correctElement = [elemAttributes.get(i) for i in elemAttributes if
elemAttributes.get(i) == item]
if correctElement:
print "FOUNDDDDDD IT", child
xmlElem = child
break
listMinusOne = [i for i in treeViewItems if not i == item]
print " XML ELm", xmlElem
gatherXMLElementInfo(listMinusOne, xmlElem)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/0d728094-33ab-40f5-a45a-8ca462044ae9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.