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.
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?
So i figured it out. This is what i needed.
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.
@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.
#Welcome to the world of Python
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.