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

    Deleting animation tracks for Shader Effector

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 300 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 14/09/2013 at 15:08, xxxxxxxx wrote:

      I am trying to delete all animation tracks in the document.

      The following code successfully removes all tracks except those under "Shader Properties" in the shader effector objects—for instance, the gradient property. Do I need to access these particular tracks through some other means? Are these tracks somehow different from the others?

      Thanks.

      import c4d
      from c4d import documents

      def GetNextObject(obj) :
        if obj==None:
            return None
       
        if obj.GetDown() :
            return obj.GetDown()
       
        while not obj.GetNext() and obj.GetUp() :
            obj = obj.GetUp()
           
        #print (obj)
       
        return obj.GetNext()

      def RemoveTracks(obj) :

      for track in obj.GetCTracks() :
            #if (track.GetCurve().GetKeyCount() > 0) :
            track.Remove()
       
      def main() :
        obj = doc.GetFirstObject()
        if obj==None: return
       
        while obj:
            RemoveTracks(obj)
            obj = GetNextObject(obj)
           
        c4d.EventAdd()
       
      if __name__=='__main__':
        main()

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

        On 14/09/2013 at 16:22, xxxxxxxx wrote:

        I am not sure how this is meant. You are stepping though all BaseObjects in the document 
        and remove all CTracks containing at least one Ckey. A BaseShader is obviously not a BaseObject 
        and therefore it will not get covered.

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

          On 14/09/2013 at 22:10, xxxxxxxx wrote:

          Thank you. That was very helpful.

          Here is the updated code for anyone else who might have this issue.

          import c4d
          from c4d import documents

          def GetNextObject(obj) :
            if obj==None:
                return None
           
            if obj.GetDown() :
                return obj.GetDown()
           
            while not obj.GetNext() and obj.GetUp() :
                obj = obj.GetUp()
               
           
            return obj.GetNext()

          def RemoveTracks(obj) :
           
            for track in obj.GetCTracks() :
                #if (track.GetCurve().GetKeyCount() > 0) :
                track.Remove()
               
            shader = obj.GetFirstShader()
            shadertree(shader)

          def shadertree(shader) :
           
            while(shader) :
               
                shaderTracks = shader.GetCTracks()
                for shaderTrack in shaderTracks:
                    shaderTrack.Remove()
                
                # Check for child shaders
                if shader.GetDown() : shadertree(shader.GetDown())
                # Get the next shader
                shader = shader.GetNext()

          def main() :
            obj = doc.GetFirstObject()
            if obj==None: return
           
            while obj:
                RemoveTracks(obj)
                obj = GetNextObject(obj)
               
           
            c4d.EventAdd()
           
          if __name__=='__main__':
            main()

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