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

How to get list of all MyPlugin instances?

Author
Message
  Topic Search Topic Search
dmitry82 View Drop Down
Member
Member


Joined: 2016 Oct 15
Location: Moscow
Online Status: Offline
Posts: 13
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:
<<<Main.cpp>>>
def PLUGIN_ID = 1234321
class MyTagPlugin: TagData {
...
...
MyTagPlugin::MyTagPlugin()
{
GePrint("---MyTag constructor---");
}

Bool MyTagPlugin::Init(GeListNode *node)
{
    GePrint("init...");
    pluginStorage = GetActiveDocument()->GetDataInstance()->GetContainer(PLUGIN_ID);
//    ERROR SECTION
/*
    index = bc.GetInt32(0,0)+1;
    pluginStorage.SetInt32(0,index);
    pluginStorage.SetLink(index, (BaseTag*)node);
*/
}

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

<<<Output>>>
Creating plugin storage
---MyTag constructor---
init...
---MyTag constructor---
init...

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
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1878
Direct Link To This Post Posted: 2018 Aug 06 at 2:50am
Hi,

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.

Cheers,
Andreas
SDK Support Engineer
Back to Top
dmitry82 View Drop Down
Member
Member


Joined: 2016 Oct 15
Location: Moscow
Online Status: Offline
Posts: 13
Direct Link To This Post Posted: 2018 Aug 18 at 9:52am
Hi, Andreas.

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


What I wanted to create is some kind of visibility switcher that gonna let me easely show/hide different groups of objects in my scene.


















Each instance of MyTag "knows" 4 things:
1)parameter number (i mean [c4d.ID_USERDATA,param_num] of controller object)
2)active parameter value
3)active layer
4)inactive layer

I'm creating controller object which contains different parameters, and when value of some parameter is changed, python script sends message to all instances of MyTag with number of parameter that was changed and it's new value. (*)
If (new_value==active_value) then (layer=active_layer), else (layer=inactive_layer)
(*) That's the step where I needed whole list of MyTag-s. I avoided this problem by creating MyTag list within my python code.

----------------
UPD (offtopic):
BTW, Andreas, there's definetely something wrong with photometric light sources in C4D.
I think it's a bug.


Edited by dmitry82 - 2018 Aug 19 at 12:27am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1878
Direct Link To This Post Posted: 2018 Aug 24 at 6:17am
Hi,

I'm actually not quite sure, if we still have an open question here. Please forgive.

For the IES lights I'd recommend to submit the bug to our user support: How can we help?

Cheers,
Andreas
SDK Support Engineer
Back to Top

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.109 seconds.