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

    Writing data to the .c4d file

    Cinema 4D SDK
    r20 python
    4
    26
    15.8k
    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.
    • CairynC
      Cairyn @A Former User
      last edited by

      @blastframe For me, it works fine this way. Did you really "close and reopen" the document? Not "save", "close", "load"? Because if you just close the document, the data from the container is gone, which leads to your error message.

      The Q regarding MyUniqueId vs. PLUGIN_ID is not relevant (probably typed in a hurry), you can use either. But the ID value should come from Maxon in the end, so you avoid collisions with existing IDs.

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @Cairyn
        last edited by A Former User

        @Cairyn I'm a little embarrassed, but you're right. I wasn't saving properly (I think just saving the Script) then going to the document in Recent Files. I'll mark this solved.

        Thank you all - @Cairyn ,@zipit ,@m_magalhaes .

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          you could use the same ID, you just have to be sure that you are the only one to use that ID to store datas.
          That's why we use plugin's ID.

          Cheers
          Manuel.

          MAXON SDK Specialist

          MAXON Registered Developer

          ? 1 Reply Last reply Reply Quote 0
          • ?
            A Former User @Manuel
            last edited by A Former User

            @m_magalhaes Thanks, Manuel.

            How would I delete the data of an individual sub-BaseContainer in the case of your script?

            I've tried several methods below but the doc[MyUniqueId][1000] still shows data in the print call.

            bc = doc.GetDataInstance().GetContainer(MyUniqueId)
            print bc.RemoveData(1000)
            # True 
            print doc[MyUniqueId].RemoveData(1000)
            # True
            doc[MyUniqueId].FlushAll()
                
            print doc[MyUniqueId][1000]
            #hello
            

            I was able to delete all of the data this way, but what if I want to keep the data in subBc[2000]?

            docBC.RemoveData(MyUniqueId)
            

            Thank you!

            1 Reply Last reply Reply Quote 0
            • ManuelM
              Manuel
              last edited by Manuel

              hello,

              there's a difference between GetContainer and GetContainerInstance
              The first return a copy of the container the second the original link.
              So either you retrieve a copy and set back the container to the parent with SetData and/or SetContainer
              or you retrieve the original link and the changes are reflected immediately.

              You can also use del that is pythonic

                  bc = doc.GetDataInstance().GetContainerInstance(MyUniqueId)
                  bc.RemoveData(2000)
                  #del (bc[2000])
              

              Cheers,
              Manuel

              MAXON SDK Specialist

              MAXON Registered Developer

              ? 1 Reply Last reply Reply Quote 1
              • ?
                A Former User @Manuel
                last edited by A Former User

                @m_magalhaes said in Writing data to the .c4d file:

                You can also use del that is pythonic

                    bc = doc.GetDataInstance().GetContainerInstance(MyUniqueId)
                    bc.RemoveData(2000)
                    #del (bc[2000])
                

                Wonderful, @m_magalhaes , thank you so much!

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