Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. robocopatrick
    R
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    robocopatrick

    @robocopatrick

    0
    Reputation
    16
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    robocopatrick Unfollow Follow

    Latest posts made by robocopatrick

    • RE: Execute python tag only when hierarchy changes

      @m_adam Thank you for your idea and for even providing a sample code. Simple but brilliant idea to check for the frame difference to see if cinema is playing back. This will help optimize some other scripts of mine and be useful in the future. Side note: I didn't quite understand why in this case i would use the exeCount but it may be helpful in other scripts. I ended up with this and am quite happy with the solution. Thanks again!

      import c4d
      from c4d import gui
      
      ##################################################
      #    This tag sets all children of the object it is on
      #    to the layer that object is on.
      ##################################################
      
      global oldFrame
      oldFrame = None
      
      def GetCurrentFrame():
          doc = op.GetDocument()
          fps = doc.GetFps()
          currentFrame = doc.GetTime().GetFrame(fps)
          return currentFrame
      
      def main():
          global layer, oldFrame
      
          # dont execute if there is no base draw
          bd = doc.GetActiveBaseDraw()
          if bd is None:
              return
      
          # dont execute during playback
          currentFrame = GetCurrentFrame()
          if currentFrame != oldFrame:
              oldFrame = currentFrame
              return
      
          # ELSE: Run the rest of the script normally
          obj = op.GetObject()
          layer = obj.GetLayerObject(doc)
          useName = obj[c4d.ID_USERDATA,1]
      
          # option: set objects name to layer name
          if layer and useName:
              layerName = layer.GetName()
              obj.SetName(layerName)
      
          # get all children and sets layer to objects layer
          allchildren(obj, obj.GetNext())
      
      def allchildren(obj,next):
          while obj and obj != next:
              if obj:
                  obj.SetLayerObject(layer)
              allchildren(obj.GetDown(),next)
              obj = obj.GetNext()
          return True
      
      posted in Cinema 4D SDK
      R
      robocopatrick
    • Execute python tag only when hierarchy changes

      Hi, I have a python tag on an object that sets the objects children to the same layer as the object. But there is no necessity to execute the python tag every frame during playback. I was wondering how to tell the tag to only execute the main part of the code, when there is a change in the overall hierarchy or better yet: only if the children of the object changes.

      It feels like there is a simple solution to this that I am not seeing. I am grateful for any help!

      import c4d
      from c4d import gui
      
      ##################################################
      #    This tag sets all children of the object it is on
      #    to the layer that object is on.
      ##################################################
      
      def main():
          global layer
          
          obj = op.GetObject()
      
          # This somehow always return 0, regardless of childrens hierarchy or parameter changes.
          print ("children: " + str( obj.GetDirty(c4d.DIRTYFLAGS_CHILDREN) ))
          
          # This also always return 0, regardless of childrens hierarchy or parameter changes.
          print ("description: " + str( obj.GetDirty(c4d.DIRTYFLAGS_DESCRIPTION) ))
          
          # This increments by one on basically every click anywhere.
          print ("data: " + str(  obj.GetDirty(c4d.DIRTYFLAGS_DATA) ))
      
      
          layer = obj.GetLayerObject(doc)
      
          allchildren(obj, obj.GetNext())
      
      def allchildren(obj,next): # Scan obj hierarchy and set childrens layer
          while obj and obj != next:
              if obj:
                  obj.SetLayerObject(layer)
              allchildren(obj.GetDown(),next)
              obj = obj.GetNext()
      
          return True
      
      posted in Cinema 4D SDK
      R
      robocopatrick