PDA

View Full Version : Recursive Parser - Python


Per-Anders
10-29-2010, 09:41 PM
See here : http://www.per-anders.net/wiki/Python_Object_Iteration (http://www.per-anders.net/w/index.php?title=Python_Object_Iteration)

Hmm, interesting it set my post before the OP's, seems there's some problems with CGTalk today.

mayajunky
10-29-2010, 09:44 PM
Well after an inquiry here from fish-msk about a specific script I've come to the conclusion there may be times I need to parse through an entire scene or very large hierarchy to check for certain types of objects etc... I got stuck in a hurry thinking about it, with my limited programming experience. How would you for instance parse through the example hierarchy in the image attached below? Maybe I'm over thinking it? Even if there are a variety of branch styles in a tree, really I suppose every object is next in the list when you expand the entire tree. Or so I need some sort of recursive parser? ( Which I would really need to read into ) Or is it easier then that? anyone have any helpful links. suggestions, input, or examples on the subject?

Thanks!

mayajunky
10-29-2010, 09:58 PM
Hmmm interesting. See that's the disadvantage of not knowing oop that well. Is definatly a different way of thinking. :P Thanks for the example Per, will break it down and test it out. :)

The first thing that throws me in the block of code is... while myobject: lol - not a good sign huh.
The way I'm reading that is it enters the loop as long as something is in the scene ( the container is filled with the first object ), then rebinds the myObject container on every iteration as long as the conditions are met from the description. Once it makes it through all the objects in the scene, GetNextObject() returns false, breaking out of the while loop?

Is that close at least?

Per-Anders
10-29-2010, 10:31 PM
You're roughly right. The description at the top in the OverView section and the animated GIF show what's happening and how the GetNextObject(op) function works.

In the main routine the object is retrieved, the code then enters the while loop, where you can do what you want to that object, at the end of each while loop the object is replaced (set) by the next object found using the GetNextObject(op) function.

CGTalk Moderation
10-29-2010, 10:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.