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

    can I have a callback when I close the c4d?

    Cinema 4D SDK
    4
    8
    1.2k
    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.
    • L
      Ling
      last edited by Ling

      can I have a callback when I close the c4d ?
      I want to rewrite c4dsymbols file and strings files in res folder when closing c4d.
      because I don't know whether c4d would crash for the changes of c4dsymbols file and strings files in res folder when c4d is running.
      I guess that c4d should not crash for changes.
      but I don't want to risk changing text of files above when c4d is running if I have other solutions.

      1 Reply Last reply Reply Quote 0
      • C4DSC
        C4DS
        last edited by C4DS

        I am wondering why anyone would want to rewrite c4dsymbols and string files dynamically, as there are probably better solutions to handle what you are trying to achieve. Even if that requires a complete redesign of your plugin.

        That said, you have PluginEnd() which is called when your plugin is unloaded
        (see https://developers.maxon.net/docs/cpp/2023_2/page_manual_module_functions.html)
        Or you could react to C4DPL_ENDPROGRAM or C4DPL_ENDACTIVITY, as mentioned in above link.

        Not knowing what you're trying to achieve it's difficult to point you to a good solution, but I would suggest rethinking the whole concept of your plugin and avoid rewriting the files dynamically.

        1 Reply Last reply Reply Quote 0
        • L
          Ling
          last edited by

          @c4ds thanks. I can not find pluginEnd() in Python.
          why I want to rewrite res files is that I want to make the plugin name with multiple languages can be changed in the UI by users.
          with a lot of difficults, finally I choose to use a json file with string plugin name. it means that plugin name with only one language can be created.
          I can use json file with multiple languages too.but it is not more flexible than c4d strings file in res.

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @Ling
            last edited by ferdinand

            Hello @Ling,

            thank you for reaching out to us and thank you @C4DS for providing help. PluginEnd() is a function that only is assumed to exist in C++. The Python interpreter does not try to call a PluginEnd(), but instead expects users to handle such tasks directly via PluginMessage() with the message id C4DPL_END, i.e., one must implement a function called PluginMessage() in its *.pyp file and then listen for that message id.

            We would however not recommend modifying the description resources of a plugin on disk, as this is not something that is intended to be done. If you want to provide a localized version of your plugin, you should make use of the bultin localization system of Cinema 4D which effectively boils down to providing multiple 'strings_xx-XX' folders. The naming conventions and procedures are being explained in the C++ manual Plugin Development: Plugin Resources. If you want to support a language other than the built-in ones, you should solve this via dynamically overwriting the description element strings (DESC_NAME, DESC_SHORT_NAME, DESC_CYCLE, etc.) at runtime via NodeData::GetDDescription. Such additional language could be defined in JSON as lined out by you, but it would always shadow the currently active built-in language, as Cinema 4D does automatically pick the language settings for your plugin via the global language settings and the string translations your plugin does provide.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            L 3 Replies Last reply Reply Quote 0
            • L
              Ling @ferdinand
              last edited by

              @ferdinand I think what I want is:
              import c4d
              import os

              def PluginMessage(id, data):
              if id == c4d.C4DPL_ENDPROGRAM:
              path="T:\PythonDeveopment\test.txt"
              with open(path, "w") as file:
              file.write("test")
              return True
              return False

              it gets me a callback when c4d is being closing as Python SDK said

              1 Reply Last reply Reply Quote 0
              • L
                Ling @ferdinand
                last edited by Ling

                @ferdinand Thank for your suggestions!

                1 Reply Last reply Reply Quote 0
                • L
                  Ling @ferdinand
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • kbarK
                    kbar
                    last edited by

                    You should definitely be using the built in language system that C4D has. You have string files in your resource folder. One for each language that you want to support. Then C4D handles all this for you and will use the appropriate string file depending what language C4D is set to use (which you change via the preferences->Interface section). This is what @ferdinand posted already above, I just wanted to re-iterate this.

                    https://www.gamelogicdesign.com
                    https://www.plugins4d.com

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