Dynamically update a dropdown/cycle

On 22/02/2013 at 01:58, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R14 
Platform:   Windows  ;   
Language(s) :     C++  ;


I've just recently started exploring plugin development for C4D in C++. Coming from Python I now find myself struggling with the most simple things, which I pretty much expected (Never been a C++ buff to  begin with 😉 ).
At the moment I'm running into a brick wall trying to dynamically set the contents of a dropdown menu in my descriptions. I'm writing an ObjectData plugin and I want the dropdown to reflect the changes being made by the user. Here is what I've done so far:

BaseObject *op = (BaseObject* )node;  
BaseContainer *data = op->GetDataInstance();  
data->SetReal(MY_PARAMETER, 1.0);  
// Until here it works, but the next lines is where the trouble starts  
BaseContainer listBC;  
listBC.SetString(0, String("Test"));  
BaseContainer bc = GetCustomDataTypeDefault(DTYPE_LONG);  
bc.SetString(DESC_NAME, "List");  
bc.SetContainer(DESC_CYCLE, listBC);  
data->SetParameter(CHANNEL_NAMES, bc);  

To be honest I've just butchered the last part together from pieces of this post https://plugincafe.maxon.net/topic/6616/7177_dynamic-drop-down-list-in-ressource so it's no wonder it's not working. I also realize, that Kuroyume said to place the code inside an overridden GetDDescription() function, but that also didn't work for me.

Isn't there a quick and efficient way to do what I want? Again, sorry for the noobish question, but everyone has to start somewhere, right? 🙂


On 22/02/2013 at 03:24, xxxxxxxx wrote:

The code must be inside GetDDescription() .

Something like this. (not tested)

    Bool LookAtCamera::GetDDescription(GeListNode *node, Description *description,DESCFLAGS_DESC &flags)
    	if (!description->LoadDescription(node->GetType())) return FALSE;
    	const DescID *singleid = description->GetSingleDescID();
    	DescID cid = DescLevel(6001, DTYPE_LONG, 0);
    	if (!singleid || cid.IsPartOf(*singleid,NULL)) // important to check for speedup c4d!
    		BaseContainer listBC;
    		listBC.SetString(0, String("Test0"));
    		listBC.SetString(1, String("Test1"));
    		BaseContainer bc = GetCustomDataTypeDefault(DTYPE_LONG);
    		bc.SetString(DESC_NAME, "List");
    		bc.SetContainer(DESC_CYCLE, listBC);
    		if (!description->SetParameter(cid, bc, DescLevel(0))) return TRUE;
    	return TRUE;

On 22/02/2013 at 04:35, xxxxxxxx wrote:

Thanks Remo, this works just perfect. I'm still kinda amazed at how complicated it is to implement this (relatively) simple behavior.
I can't say I fully understand your code though. For instance, I don't really get, what the if statement is checking. The in the SDK GetSingleDescID() is not further explained (Private).
In any case, everythings working for me so far, so thanks a lot for saving me from more frustration.

Guess I have so much more to learn. 🙂

On 22/02/2013 at 08:23, xxxxxxxx wrote:

If you are new to the C++ SDK you might benefit from visiting my plugins website:

The plugins are mostly just simple working examples of many common "How-To" SDK questions that are not explained well (or at all) in the SDK.
All of the plugins there include the source code with comments in them to make it easier to learn the code.


On 22/02/2013 at 10:13, xxxxxxxx wrote:

Thanks Scott, your example projects look really helpful. I wish I knew of these when I was still learning Python. Might have saved me a sleepless night or two. 😉
It's really generous of you that you make these available for everyone to learn.