Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Detecting if a BaseObject is a Generator [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 614 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      Hi,

      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()) :   
              return   
        
          #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,   
                                c4d.Onull,   
                                c4d.Ospline,   
                                c4d.Ocamera,   
                                c4d.Ofloor,   
                                c4d.Osky,   
                                c4d.Oenvironment,   
                                c4d.Oforeground,   
                                c4d.Obackground,   
                                c4d.Ojoint,   
                                ]   
              if obj_type not in exempted_types:   
                  return False   
        
          return True   
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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  
          else:  
              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
        Martin

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          Hello,

          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("Generator")  
          else:  
               print("No Generator")  
          

          best wishes,
          Sebastian

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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. 🙂

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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."   
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post