Hello!
I have a question about persistently storing data in a command in c++. I have found that i can use CRhinoSettings for this. However, I run into some trouble using. Below is a very simple example command.
CRhinoCommand::result CCommandNewTestCommand::RunCommand(const CRhinoCommandContext& context)
{
int TestCounterValue = 0;
CRhinoSettings CommandSettings = this->Settings();
if (CommandSettings.GetInteger(L"TestCounter", TestCounterValue))
{
RhinoApp().Print(L"Load succesfull!\n");
}
ON_wString str;
str.Format(L"Counter: %i\n", TestCounterValue);
RhinoApp().Print(str);
TestCounterValue++;
CommandSettings.SetInteger(L"TestCounter", TestCounterValue);
return CRhinoCommand::success;
}
I expect this to simply increment the counter every time I run the command. However, this is the output I get:
It does increment between successive debug runs, as can be seen from the fact that the counter has gotten up to 14. This is surprising to me. In order to check if this is me having the wrong expectations.
Below is a similar command in c#.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
double DoubleVal;
string Key = "VerySpecificKey";
if (this.Settings.TryGetDouble(Key, out DoubleVal))
{
RhinoApp.WriteLine("Loading successfull!");
DoubleVal = DoubleVal + 1.0f;
}
else
{
DoubleVal = 8.12;
}
this.Settings.SetDouble(Key, DoubleVal);
RhinoApp.WriteLine("The {0} command set the value of {1} to {2}", EnglishName, Key, DoubleVal);
// ---
return Result.Success;
}
This produces the output:
This is more along the lines of what I expect the output to be. The question then is: what am I doing wrong in c++ that I can not get the same result?