Get Checkbox state [SOLVED]
-
On 30/01/2017 at 01:00, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R17
Platform: Windows ;
Language(s) : C++ ;---------
Hello everyone,I'm new to C4D C++ plugin dev, and I have a small checkbox problem. Inside the cinema4dsdk project, in gedialog_gadgets.cpp there is this code :
{...} case(DIALOGELEMENTS::RADIO_TEXT) : { Bool checked; if (GetBool(ID_DYMAMIC_GADGET, checked)) { if (checked) SetString(ID_CONSOLE, "checked"); else SetString(ID_CONSOLE, "not checked"); } break; }{...}
It's called whenever you click a "Read Data" button. In my own plugin, i have a similar setup, but the code gets called from the Command() function override of my GeDialog :
virtual Bool Command(Int32 id, const BaseContainer &msg) { switch (id) { case (DLG_CHK_ACTIVE) : { Bool checked; if (GetBool(DLG_CHK_ACTIVE, checked)) { if (checked) { WriteLineToConsole("Active."); } else { WriteLineToConsole("Inactive."); } } } break; } return TRUE; }
My problem is that whether i check or uncheck the checkbox, I get an "Inactive." line on my console. My WriteLineToConsole() function works as expected and its purpose is just to add a little prompt (later a timestamp and useful info) to the line.
Here is what i get after clicking 6 times on my checkbox :
I would expect something like :
"-> Active.
-> Inactive.
-> Active.
-> Inactive.
-> Active.
-> Inactive."Is there anything I am doing wrong?
-
On 30/01/2017 at 01:58, xxxxxxxx wrote:
Hmmmm....
I tweaked my code a bit, to print ids in my console, get info from the msg argument and thing like that. In the end i ended up with the same code i posted previously and the checkbox works as expected...
-
On 30/01/2017 at 05:00, xxxxxxxx wrote:
Hi aTom, thanks for writing us and welcome to the PluginCafè.
With reference to your question, please note that the way you're trying to recover the checkbox value is improper and lead to this wrong behavior. You have instead to rely on the BaseContainer instance provided as "msg" parameter in the Command() method to retrieve the value of the checkbox or of any other item which has originally fired the Command() call.
By accessing the value provided by the BaseContainer instance via GetData() you're accessing the referring GeData instance actually responsible to provide you with the GUI element value.... ... switch (id) { case CHECKBOX_ID: GeData actionValue = msg.GetData(BFM_ACTION_VALUE); if (actionValue.GetBool()) GePrint("checkbox is checked"); else GePrint("checkbox is unchecked"); break; } ... ...
Best, Riccardo
-
On 30/01/2017 at 08:10, xxxxxxxx wrote:
Hi Knickknac,
Thank you for your answer, i understand the BaseContainer object a lot better now.