access sound attributes using python API



  • 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



  • 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 :P for people starting in c4d py dev!

    Not sure how to set this to SOLVED



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



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



  • @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 :D just a couple weeks back.



  • 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)
    


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