Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

How to get list of all MyPlugin instances?

 Post Reply Post Reply
dmitry82 View Drop Down

Joined: 2016 Oct 15
Location: Moscow
Online Status: Offline
Posts: 12
Post Options Post Options   Quote dmitry82 Quote  Post ReplyReply Direct Link To This Post Topic: How to get list of all MyPlugin instances?
    Posted: 2018 Aug 04 at 5:32am

User Information:

Cinema 4D Version:   19 
Platform:   Windows  ;   
Language(s):     C++  ;   


At first, I thought that it's a very simple task.. My mistake.:-/

What I tried to do is to create global storage and save link to plugin instance every time it's being created:
def PLUGIN_ID = 1234321
class MyTagPlugin: TagData {
GePrint("---MyTag constructor---");

Bool MyTagPlugin::Init(GeListNode *node)
    pluginStorage = GetActiveDocument()->GetDataInstance()->GetContainer(PLUGIN_ID);
    index = bc.GetInt32(0,0)+1;
    pluginStorage.SetLink(index, (BaseTag*)node);

Bool PluginMessage(Int32 id, void *data)
        GePrint("Creating plugin storage");
        GetActiveDocument()->GetDataIstance()->SetContainer(PLUGIN_ID, BaseContainer());

Creating plugin storage
---MyTag constructor---
---MyTag constructor---

Why Constructor and Init functions of my plugin are fired twice when each instance of it created and twice every time when I change any parameter of MyTag?
What event or function should I use instead, to catch the moment of MyTag creation?

Edited by dmitry82 - 2018 Aug 04 at 6:36am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1847
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Aug 06 at 2:50am

indeed you can not rely on Init() (or the constructor) being called just once. There are several reasons for this, one for example is related to the undo system. The correct way to be informed about the creation of your tag is to listen to the (admittedly strangely named) message MSG_MENUPREPARE. This message is sent, when the user creates a new tag from the menu (and is meant to do additional preparational work, thus its name).

May I ask, why you are trying to set up such a global directory of tag instances?

In that regard also you use of PluginMessage(C4DPL_COMMANDLINEARGS) looks a bit strange to me. The user might be working with multiple documents in parallel later on. Or he might close the scene and open a new one. The more correct approach would be, to check the existence of your BaseContainer later on, when you actually want to access it, and then create it on the fly if needed.

SDK Support Engineer
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.