can I have a callback when I close the c4d?
-
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. -
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.
-
@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. -
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 aPluginEnd()
, but instead expects users to handle such tasks directly via PluginMessage() with the message idC4DPL_END
, i.e., one must implement a function calledPluginMessage()
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 -
@ferdinand I think what I want is:
import c4d
import osdef 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 Falseit gets me a callback when c4d is being closing as Python SDK said
-
@ferdinand Thank for your suggestions!
-
This post is deleted! -
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.