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
    • Register
    • Login

    access sound attributes using python API

    Cinema 4D SDK
    r20 python
    3
    7
    1.2k
    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.
    • M
      mafster
      last edited by r_gigante

      Hi there,

      I'm wanting to access the sound tracks path attribute (and potentially other sound attributes)

      Is that possible with the python API?

      I have a null that i've created a a Special Track (Sound) on and now want to access the sound paths location as well as the time offset value.
      Any ideas how to do this?

      I can access the null object fine.

      Edit:
      I can also access the CTrack with

      obj = doc.SearchObject('sound')
      sound_track = obj.GetFirstCTrack()  # Its only going to have track on it at any point in time
      data = sound_track.?? # what to do here?
      

      Thanks!
      Jono

      M 1 Reply Last reply Reply Quote 0
      • M
        mafster @mafster
        last edited by mafster

        So i figured it out. This is what i needed.

        sound_track[c4d.CID_SOUND_NAME]
        sound_track[c4d.CID_SOUND_START]
        

        I also found out an extremely useful little thing! You can drag and drop attributes into the console to get their id....that should be on the front page of the python documentation 😛 for people starting in c4d py dev!

        Not sure how to set this to SOLVED

        mrittmanM 1 Reply Last reply Reply Quote 0
        • r_giganteR
          r_gigante
          last edited by

          Hi Mafster, thanks for reaching out us.

          We're glad to hear that the issue has been addressed already on your side and, for the sake of completeness, I'd like to point to the Python Console section in the Python Documentation.

          Last but not least, you can set a topic to be shown as a question via the "Topic Tools" menu drop down and, after doing that, set a topic solved by using the humburger menu in the post. Check here for further details on Q&A functionality.

          Best, Riccardo.

          1 Reply Last reply Reply Quote 0
          • mrittmanM
            mrittman @mafster
            last edited by

            @mafster Any chance you could share the final script? I’m trying to do something similar and running into some roadblocks 😞

            M 1 Reply Last reply Reply Quote 0
            • M
              mafster @mrittman
              last edited by mafster

              @mrittman sure thing:

              from c4d import documents
              
              doc = documents.GetActiveDocument()
              
              obj = doc.SearchObject('sound')  # "sound" is just an in-house convention...could be anything
              
              # Note there its the first track. Also convention...
              sound_track = obj.GetFirstCTrack()
              
              # Get the audio file
              audio_path = sound_track[c4d.CID_SOUND_NAME]
              
              

              If i had to get the soundtrack another way by name or something i wouldnt quite know. Im guessing using sound special track id or something might do it...im very experienced with python but complete noob to c4d 😄 just a couple weeks back.

              mrittmanM 1 Reply Last reply Reply Quote 0
              • mrittmanM
                mrittman @mafster
                last edited by mrittman

                Thanks a ton @mafster, I really appreciate it! I think what I’ve got is pretty similar. I am using a python node inside of xpresso to target sound tracks.

                I notice you’re using CID_SOUND_NAME, while I’m using CID_SOUND_START. I hardly know anything about this stuff, so I hope I’m doing it correctly haha.

                import c4d
                #Welcome to the world of Python
                
                
                def main():
                    global output_secs
                
                    output_secs = input_secs # store input_secs inside output_secs
                
                    sn = doc.SearchObject(input_name) # sound in timeline
                
                    t = sn.GetFirstCTrack() # 1st track of object
                
                    t[c4d.CID_SOUND_START] = c4d.BaseTime(output_secs)
                
                M 1 Reply Last reply Reply Quote 0
                • M
                  mafster @mrittman
                  last edited by

                  Hey @mrittman, i cant find the id names in documentation but i think CID_SOUND_START would be the timecode of when the audio starts (notice you are assigning a BaseTime object to it) CID_SOUND_NAME which i'm using is the audio file path.

                  My application is taking the audio file path and the image sequence output (as defined by the render output settings) and combining them via a subprocess using ffmpeg. If there was a way i could do it straight through c4d id prefer that! Mainly cos ffmpeg is a mission! especially when you need to shift/delay audio and what not.

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