Tag Plugin doesn't load [SOLVED]



  • On 05/02/2015 at 06:37, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R16 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi,

    I've copied the lookatcamera plugin and edited it to my needs.
    The only problem is, it doesn't load anymore.

    Here is my code inside main.cpp:

      
    #define ID_RESETROTCD 1000010  
      
    #include "c4d.h"  
    #include "c4d_symbols.h"  
    #include "resetrotcd.h"  
      
    #include "lib_description.h"  
    #include "customgui_priority.h"  
      
    class ResetRotCD : public TagData  
    {  
    public:  
      virtual Bool Init(GeListNode* node);  
        
      virtual EXECUTIONRESULT Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags);  
        
      static NodeData* Alloc(void) {return NewObjClear(ResetRotCD);}  
    };  
      
    Bool ResetRotCD::Init(GeListNode* node)  
    {  
      BaseTag* tag = (BaseTag* )node;  
      BaseContainer* dataObjectOne = tag->GetDataInstance();  
      BaseContainer* dataObjectTwo = tag->GetDataInstance();  
      
      BaseDocument* doc = C4DOS.Ge->GetActiveDocument();  
        
      dataObjectOne->GetLink(OBJECT_ONE, doc);  
      dataObjectTwo->GetLink(OBJECT_TWO, doc);  
        
      return true;  
    }  
      
    EXECUTIONRESULT ResetRotCD::Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags)  
    {  
      GePrint("The ResetRotCD-tag is executed now!");  
      return EXECUTIONRESULT_OK;  
    }  
      
    Bool PluginStart(void)  
    {  
      return RegisterTagPlugin(ID_RESETROTCD, GeLoadString(IDS_RESETROTCD), TAG_EXPRESSION | TAG_VISIBLE, ResetRotCD::Alloc, "resetrotcd", NULL, 0);  
    }  
      
    void PluginEnd(void)  
    {  
    }  
      
    Bool PluginMessage(Int32 id, void *data)  
    {  
      return TRUE;  
    }  
    

    And inside resetrotcd.h:

      
    #ifndef RESETROTCD_H__  
    #define RESETROTCD_H__  
      
    enum  
    {  
      OBJECT_ONE        = 1000,   
      OBJECT_TWO  
    };  
      
    #endif // RESETROTCD_H__  
    

    And inside resetrotcd.res:

      
    CONTAINER resetrotcd  
    {  
      NAME resetrotcd;  
      INCLUDE Obase;  
      
      GROUP ID_TAGPROPERTIES  
      {  
          LINK OBJECT_ONE {}  
          LINK OBJECT_TWO {}  
      }  
    }  
    

    Does anybody see the problem?

    PS: How do I put my code in a nice block?

    Thanks for your time and help!
    Greetings,

    Casimir Smets



  • On 06/02/2015 at 06:34, xxxxxxxx wrote:

    Hello,

    I couldn't reproduce any problem with the above code. Is there any error message in the console?

    Some things in your Init() function are problematic:

    • You are calling C4DOS. Never do that.
    • Also never call GetActiveDocument() in any NodeData function. Your node may be used in a complex render context without any "active document". If you need to know the document call GetDocument().
    • Also, never use a pointer without checking if the pointer is valid.
    • Always keep your Init() function simple and stable. It may be called multiple times when different objects are handled.

    To format code use the CODE tag.

    Best wishes,
    Sebastian



  • On 12/02/2015 at 03:28, xxxxxxxx wrote:

    Hi,

    No, I don't have any error message in the console nor a build fail in Xcode.
    I have adjusted the Init function and my main.cpp file now looks like this:

      
    #define ID_RESETROTCD 1000010  
      
    #include "c4d.h"  
    #include "c4d_symbols.h"  
    #include "resetrotcd.h"  
      
    #include "lib_description.h"  
    #include "customgui_priority.h"  
      
    class ResetRotCD : public TagData  
    {  
    public:  
      virtual Bool Init(GeListNode* node);  
        
      virtual EXECUTIONRESULT Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags);  
        
      static NodeData* Alloc(void) {return NewObjClear(ResetRotCD);}  
    };  
      
    Bool ResetRotCD::Init(GeListNode* node)  
    {  
      BaseTag* tag = (BaseTag* )node;  
      if (!tag) return NULL;  
      BaseContainer* dataObjectOne = tag->GetDataInstance();  
      if (!dataObjectOne) return NULL;  
      BaseContainer* dataObjectTwo = tag->GetDataInstance();  
      if (!dataObjectTwo) return NULL;  
      
      BaseDocument* doc = tag->GetDocument();  
      if (!doc) return NULL;  
        
      dataObjectOne->GetLink(OBJECT_ONE, doc);  
      dataObjectTwo->GetLink(OBJECT_TWO, doc);  
        
      return true;  
    }  
      
    EXECUTIONRESULT ResetRotCD::Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags)  
    {  
      GePrint("The ResetRotCD-tag is executed now!");  
      return EXECUTIONRESULT_OK;  
    }  
      
    Bool PluginStart(void)  
    {  
      return RegisterTagPlugin(ID_RESETROTCD, GeLoadString(IDS_RESETROTCD), TAG_EXPRESSION | TAG_VISIBLE, ResetRotCD::Alloc, "resetrotcd", NULL, 0);  
    }  
      
    void PluginEnd(void)  
    {  
    }  
      
    Bool PluginMessage(Int32 id, void *data)  
    {  
      return TRUE;  
    }  
    

    Also I have changed the function RegisterLookAtCamera to PluginStart, and added PluginEnd and PluginMessage, because I got those errors in Xcode (function missing / all 3 of them).

    Could the problem be this? Wrong function to register the plugin which never gets called?

    Thanks for your help and time!!

    Greetings,
    Casimir



  • On 12/02/2015 at 04:26, xxxxxxxx wrote:

    Hello,

    it looks like there is still one thing missing. When you want to use resource files you have to make sure these files are loaded; Cinema won't do this automatically. Typically you init the resources in PluginMessage() reacting to the C4DPL_INIT_SYS message. Take a look at the SDK example project.

    Best wishes,
    Sebastian



  • On 12/02/2015 at 05:17, xxxxxxxx wrote:

    Hello,

    also, on a second look, your Init() function is still problematic. Init() is called after the object is created. At this point the object is not yet a part of a document, so GetDocument() will not work here.

    When you then return false, Cinema will assume that the object could not be initiated and will destroy the object. The Init() function is used to define default values and to prepare member variables, not to read anything.

    Best wishes,
    Sebastian



  • On 12/02/2015 at 05:51, xxxxxxxx wrote:

    Hi,

    Well, I tried that. Now, I could find the plugin inside my tags, but it hasn't been loaded or something like that. The name is StrNotFound, so at least it has been looking for my resource files.

    I have adjusted PluginMessage to:

      
    Bool PluginMessage(Int32 id, void *data)  
    {  
      switch (id)  
      {  
          case C4DPL_INIT_SYS:  
              if (!resource.Init())  
                  return false;  
                
              return true;  
                
          case C4DMSG_PRIORITY:  
              // React to this message to set a plugin priority (to determine in which order plugins are initialized or loaded.  
              // SetPluginPriority(data, mpriority);  
              return true;  
                
          case C4DPL_BUILDMENU:  
              // React to this message to dynamically enhance the menu  
              // EnhanceMainMenu();  
              break;  
                
          case C4DPL_COMMANDLINEARGS:  
              // Sample implementation of command line rendering:  
              // void CommandLineRendering(C4DPL_CommandLineArgs* args);  
              // CommandLineRendering((C4DPL_CommandLineArgs* )data);  
              break;  
                
          case C4DPL_EDITIMAGE:  
              return false;  
      }  
        
      return false;  
    }  
    

    I guess I'm getting close to fixing my problem!
    Thanks for your help and time,

    Greetings,
    Casimir



  • On 12/02/2015 at 06:59, xxxxxxxx wrote:

    Hi,

    So, if I understand it correctly, I should get my values inside execute?
    Like this:

      
    EXECUTIONRESULT ResetRotCD::Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags)  
    {  
      BaseContainer* dataObjectOne = tag->GetDataInstance();  
      if (dataObjectOne)  
      {  
          dataObjectOne->GetLink(OBJECT_ONE, doc);  
      }  
        
      BaseContainer* dataObjectTwo = tag->GetDataInstance();  
      if (dataObjectTwo)  
      {  
          dataObjectTwo->GetLink(OBJECT_TWO, doc);  
      }  
      
      return EXECUTIONRESULT_OK;  
    }  
    

    Also I think there is something badly wrong inside my PluginMessage().
    The only thing I didn't use from the example is RegisterExampleDataType, but I don't think this is causing the problem.

    Greetings,
    Casimir



  • On 12/02/2015 at 08:53, xxxxxxxx wrote:

    Hello,

    yes, it is the best workflow to get the current value of a parameter when you actually need it and the value is set; in this case this is when Execute() is called.

    Looking again at your resource file I see that you you use INCLUDE Obase; which doesn't make sense since you are creating a tag and not an object. You should include Texpression like in the original example.

    Best wishes,
    Sebastian



  • On 13/02/2015 at 03:03, xxxxxxxx wrote:

    Hi,

    The reason I tried that is because in Python tag-plugins you can use Obase without having any problems.
    But that clearly doesn't go for Cpp tag plugins.

    I've changed it and now my plugin works! Very much thanks for that!!! :)

    Yet I have still one problem, the name of the plugin still is "StrNotFound".
    Could that be something inside my RegisterTagPlugin? Maybe GeLoadString?

    Thanks for your help and time!!
    Greetings,
    Casimir



  • On 13/02/2015 at 03:31, xxxxxxxx wrote:

    Hi,

    Well, it's nothing inside my RegisterTagPlugin!
    I simply forgot to add and edit c4d_strings.str in my strings_us directory.
    I guess this will NEVER happen again! :D

    Thanks for all your help Sebastian!!
    You can mark this post as solved/closed.

    Greetings,
    Casimir



  • On 13/02/2015 at 04:38, xxxxxxxx wrote:

    Including Obase will work for CPP Tag plugins, too. The only question us, why would you want to include Obase in a Tag plugin?


Log in to reply