Detecting if a BaseObject is a Generator [SOLVED]

  • On 12/06/2015 at 16:10, xxxxxxxx wrote:


    Is it possible to detect if an object has a Generator checkmark? I can detect if a generator is unchecked, but for objects that don't have a checkmark (like a Null) they always return true when I try:

    generator_on = obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG]   

    I'm currently checking objects against a manually generated list of exempted types, but I'd like to know if there's a better way, because if I forget to include a type, or a new object type is added to cinema, my code will break:

    def is_muted(obj) :   
        """Return True if object is hidden in editor, renderer, and disabled."""   
        if debug:   
            print "is_muted(%s)" % (obj.GetName())   
        if (obj is None) or (not obj.IsAlive()) :   
        #Determine visibility based on `Visible in Editor/Renderer` not set to `Off`   
        visible_in_editor = (obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] != 1)   
        visible_in_render = (obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] != 1)   
        if visible_in_editor or visible_in_render:   
            if debug:   
                print "Visible in editor/renderer", obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]   
            return False   
        #If the generator flag is on, and it's not a special type, the object isn't mute.   
        generate = obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG]   
        if generate:   
            if debug:   
                print "Generate is on"   
            obj_type = obj.GetType()   
            exempted_types = [c4d.Opolygon,   
            if obj_type not in exempted_types:   
                return False   
        return True   

  • On 13/06/2015 at 01:53, xxxxxxxx wrote:

    Hi Donovan,

    it´s a workaround for sure and there might be a simpler method, but trying to access the parameter gives you a clear result.

      generator_check = op[c4d.ID_BASEOBJECT_GENERATOR_FLAG]  
      if generator_check == 1:  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = 0  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = 1  
      if not op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == generator_check:  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = generator_check  
          print "real generator"  

    Best wishes

  • On 13/06/2015 at 04:32, xxxxxxxx wrote:


    an object is a generator when you use the OBJECT_GENERATOR flag when you register that object. You can read these flags using GetInfo(). Then you can check if the generator flag is set with something like this:

    info = op.GetInfo()  
    if info & c4d.OBJECT_GENERATOR:  
         print("No Generator")  

    best wishes,

  • On 13/06/2015 at 06:40, xxxxxxxx wrote:

    It also has a checkmark when its a deformer, in case you want to
    check that as well, use the OBJECT_MODIFIER flag. :)

  • On 14/06/2015 at 12:28, xxxxxxxx wrote:

    @monkeytack - I was hoping to avoid getting/setting the generator state as I'm using it in the Command Enable/Toggle code and it felt like that could get expensive, but that was going to to be my next strategy. Thanks for the working code.

    @s_bach - That's exactly what I was looking for. It feels like this might bear mentioning in the BaseObject docs as that's where I thought to look for the information.

    @niklas - Perfect, that makes it even more robust.

    Thank you guys! Here's my code for testing if something is an active generator/deformer.

        #Is it a generator or deformer?   
        obj_info = obj.GetInfo()   
        is_generator = obj_info & c4d.OBJECT_GENERATOR   
        is_deformer = obj_info & c4d.OBJECT_MODIFIER   
        if is_generator or is_deformer:   
            print "Obj is a generator/deformer"   
            #Is it turned on?   
            generate = obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG]   
            if generate:   
                print "Generator/deformer is active."   

  • On 15/06/2015 at 11:44, xxxxxxxx wrote:

    I think you should prefer obj.GetDeformState() over reading the ID_BASEOBJECT_GENERATOR_FLAG parameter.

Log in to reply