Jump to content

Jimmy Georgie

Limited Member
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • First Name
    James
  • Last Name
    Grean

Jimmy Georgie's Achievements

Newbie

Newbie (1/14)

  • First Post Rare
  • Conversation Starter Rare
  • Week One Done
  • One Month Later
  • One Year In

Recent Badges

0

Reputation

  1. Ah yeah, sorry, it was a bit a shambles I did solve it, but didn't realise I could just say "and". I found a way to do the name a bit differently, not sure what the pros and cons of each would be. So my code was like this: import c4d def main(): obj = doc.SearchObject('BloodCells') parent = obj # stores the active object in a 'parent' variable, so it always stays the same if obj: # if there is a object selected children = [] # create an empty list to store children while obj: # while there is a object (the "walker" function will return None at some point and that will exit the while loop) obj = walker(parent, obj) # set the obj to the result of the walker function if obj: # if obj is not None children.append(obj) # append that object to the children list print children # print the list childrenC = len(children) #children Count print "There are " + str(childrenC) + " objects in the hierarchy." if childrenC > 0: activeChildren = [] for c in children: # Loop Through Children, each one is "c" if c[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == True: # If the object is generator-active activeChildren.append(c) #append it into the list "activeChildren" theName = c.GetName() #what is the Object Manager name of the current object? #print theName if theName == “VirusCells": print "I found the Virus Cells Object, now you can do an action with it" else: print "Not what you were looking for!" activeChildrenC = len(activeChildren) #print “And there were " + str(activeChildrenC) + " Active Children" def walker(parent, obj): if not obj: return # if obj is None, the function returns None and breaks the while loop elif obj.GetDown(): # if there is a child of obj return obj.GetDown() # the walker function returns that child while obj.GetUp() and not obj.GetNext() and obj.GetUp() != parent: # if there is a parent of the obj and there isn't another object after the obj and the parent object is not the same object stored in "parent" obj = obj.GetUp() # it sets the current obj to that parent return obj.GetNext() # and return the object that's after that parent, not under, after :) It's probably too many lines but its more human readable, to me anyway. 🙂 Also to be clear again, for anyone else, it uses some code from Kalugin that was very nicely commented to walk the tree. Now that's it's posted I can't seem to edit the code box to put it in! Thanks!
  2. Hi all, I'm trying to figure something out but my Python is a bit fuzzy. Hope someone can clue me in. I have a semi-complex scene with enough duplicated hierarchies and objects that it's tedious to turn some things on and off, and I want to set up various nulls at the top of the object manager with helpers on them. I would like to walk through the children of a specific null, get a list of all "Activated Objects" (Generator Flags On) and return the ONE whose name matches "virus" or "xyz" whatever. So, specific null is something like obj = doc.SearchObject('BloodCells') Then walking through all children I'm doing thanks to Kalugin here (https://www.core4d.com/ipb/forums/topic/103664-little-help-about-recursive-hierarchy/ And by "active" I mean [c4d.ID_BASEOBJECT_GENERATOR_FLAG] == True: The part where I get fuzzy is how, from that list of activated objects/generators, do I return the ONE object with a specific name (as opposed to the other generators with the same name that are off). Finally, there should only ever be one matching case (if I set the project up right), but possibly including a check to count if there's more than one found, then throwing an error if so, could be useful to debug? Could I do this with a search and some clicks in the object manager? Yes. But I'm looking for a way to have this done automatically and save those clicks, which will in turn save me a lot of time over the coming weeks on this project. Thanks Edit: for some reason, some nulls are being returned in the list of activated "generators" using the code above. A null is not a generator though so why are they being returned?
  3. Hey Jamie, Sorry to raise an old thread, curious if you ever worked this out? I've been struggling myself with this for the past week. There's an example at about 58:00 in this video but no detail on how it's accomplished. Seems complicated if it involves scripts and things. https://www.youtube.com/watch?v=4fSRxlTD22M
×
×
  • Create New...

Copyright Core 4D © 2024 Powered by Invision Community