Importing/loading sound file to scene via Python
-
Hi everyone, pretty new here. I got to read the documentation and honestly amazed at how well-documented everything is.
Tho, despite of that, I'm still unable to find a way to import sound/audio file. I guess it's due to the fact that in the GUI itself, adding sound is a multi-steps process, so I'm unable to directly find the relevant method.
If anyone got any tips, it'll be appreciated, thanks!
-
I managed to search a bit more, so turns out everything related to keyframe is defined as
CTrack
. It's just a matter of determining the type/attribute.I will try to adapt the solution from this topic (it was about keyframing visibility): https://developers.maxon.net/forum/topic/13686/python-script-to-keyframe-visibility-of-object/3?_=1721442329144
With the new information regarding
CTsound
to refer to the sound special track: https://developers.maxon.net/docs/py/2024_0_0a/modules/c4d/C4DAtom/GeListNode/BaseList2D/CTrack/index.html?highlight=ctrack#c4d.CTrackAnd maybe post the result once I figure it out.
-
Turns out it's really simple, the documentation using
ID
instead ofDescID
creates unnecessary confusion. I thought they meant to insertc4d.CTsound
directly toCTrack
, but you need to follow the previous examples to useDescID
.In any case, here you go:
def create_audio_track(self, path): """Add an audio track to the selected object""" # Define a new audio track (following the documentation) descId = c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0)) track = c4d.CTrack(op, descId) track[c4d.CID_SOUND_NAME] = path op.InsertTrackSorted(track)
-
Hi @ezeuz,
Great to hear you've figured it out and thanks for sharing the solution with the community!
Cheers,
Ilia