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
    1. Maxon Developers Forum
    2. ac3
    3. Topics
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 13
    • Best 0
    • Controversial 0
    • Groups 0

    Topics created by ac3

    • A

      id PluginMessage () when the scene loaded

      Cinema 4D SDK
      • python sdk • • ac3
      12
      0
      Votes
      12
      Posts
      1.8k
      Views

      ManuelM

      hi,
      sorry I was focused on calling a command and not a script.

      Even if it's pretty simple, it's not as simple as i expected to run a python script, sorry about that.
      Be careful that you need to create the script and relaunch c4d to be able to find it by its name.

      The idea is to retrieve the ID of the script and use callCommand to execute it. (as you can do with any commandData IDs)
      you can retrieve the ScriptList with GetScriptHead witch return a GeListHead

      So you can retrieve the first with GetFirst and compare the name.
      If you find one, you can simply return it's IDs using GetDynamicScriptID and return it.

      You now just have to use CallCommand with this ID. (be aware that this CallCommand will create an undo step in the undo stack)

      So your script will be executed when a new document is loaded.

      #include "maxon/apibase.h" #include "maxon/errorbase.h" #include "maxon/errortypes.h" #include "maxon/file_utilities.h" #include "maxon/application.h" #include "c4d_general.h" #include "c4d_commanddata.h" #include "c4d_baseplugin.h" #include "c4d_scenehookdata.h" #include "c4d_baselist.h" static Int32 GetScriptID(const maxon::String& scriptName) { iferr_scope; // check all script // Retrieves the script head BaseList2D* scriptHead = static_cast<BaseList2D*>(GetScriptHead(0)->GetFirst()); // for all script for (BaseList2D* script = scriptHead; script != nullptr; script = script->GetNext()) { // retrieves the name of the script maxon::String name = script->GetName(); // if the name match the argument, return the id of the script if (name.IsEqual(scriptName)) return GetDynamicScriptID(script); } // return NOTOK if no script founded. return NOTOK; } class pc12835_scenehook : public SceneHookData { public: static NodeData* Alloc() { return NewObjClear(pc12835_scenehook); } Bool Message(GeListNode* node, Int32 type, void* data) override { if (type == MSG_DOCUMENTINFO) { DocumentInfoData* const msg = static_cast<DocumentInfoData*>(data); if (msg == nullptr) return false; // switch message sub-type switch (msg->type) { case MSG_DOCUMENTINFO_TYPE_LOAD: { // define my script name maxon::String scriptName = "myscript"_s; // search the ID of the scrip const Int32 scriptID = GetScriptID(scriptName); // if the script have been founded, execute it. if (scriptID != NOTOK) CallCommand(scriptID); break; } case MSG_DOCUMENTINFO_TYPE_UNDO: case MSG_DOCUMENTINFO_TYPE_REDO: { ApplicationOutput("undo or redo done"_s); break; } } return true; } return SceneHookData::Message(node, type, data); }; };

      Of course you need to register your sceneHookData with RegisterSceneHookPlugin

      Cheers,
      Manuel

    • A

      Get visible objects from viewport in commandline

      Cinema 4D SDK
      • • • ac3
      11
      0
      Votes
      11
      Posts
      1.8k
      Views

      ManuelM

      hi,

      I tried creating a CommandData that you could be triggered with a parameter --> not working
      I tried creating a ObjectData that could react to MSG_DOCUMENTINFO in its Message function when the document is loaded --> not working
      I tried when the program is closing --> not working

      Based on my knowledge, there's no solution for your issue.

      Cheers,
      Manuel