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

    Importing/loading sound file to scene via Python

    Cinema 4D SDK
    python 2024 windows
    2
    4
    590
    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.
    • E
      ezeuz
      last edited by

      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.

      82a08aa3-9e0c-4647-aaa0-7192181f8d1c-image.png

      If anyone got any tips, it'll be appreciated, thanks!

      1 Reply Last reply Reply Quote 0
      • E
        ezeuz
        last edited by ezeuz

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

        And maybe post the result once I figure it out.

        1 Reply Last reply Reply Quote 0
        • E
          ezeuz
          last edited by ezeuz

          Turns out it's really simple, the documentation using ID instead of DescID creates unnecessary confusion. I thought they meant to insert c4d.CTsound directly to CTrack, but you need to follow the previous examples to use DescID.

          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)
          
          i_mazlovI 1 Reply Last reply Reply Quote 0
          • i_mazlovI
            i_mazlov @ezeuz
            last edited by

            Hi @ezeuz,

            Great to hear you've figured it out and thanks for sharing the solution with the community!

            Cheers,
            Ilia

            MAXON SDK Specialist
            developers.maxon.net

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