I have a command that is almost identical in behavior except for one boolean. I really don’t want to fork my entire command code just for that boolean. What I’m trying to do is something like “MyCommand(true)” “MyCommand(false)” so I can add the command to the toolbar for with each mode. Can I do this?
I tried using CRhinoGetOption but its Option() method immediately fails no matter what I add to it.
To get around this (for now), I just subclassed the command and changed the bool. Seems to work.
class CCommandPullCageByNormal : public CCommandPullCage
{
public:
CCommandPullCageByNormal()
{
m_lockToNormal = true;
}
~CCommandPullCageByNormal() = default;
UUID CommandUUID() override
{
// {9BA9D09B-3536-47EC-93EB-202B2ED3A1BF}
static const GUID guid =
{ 0x9ba9d09b, 0x3536, 0x47ec,{ 0x93, 0xeb, 0x20, 0x2b, 0x2e, 0xd3, 0xa1, 0xbf } };
return guid;
}
const wchar_t *EnglishCommandName() override { return L"PullCageByNormal"; }
//CRhinoCommand::result RunCommand(const CRhinoCommandContext &context) override;
private:
};
static CCommandPullCageByNormal theCommand;
dale
(Dale Fugier)
July 12, 2018, 12:02am
3
Hi @gccdragoonkain ,
That certainly works. However, if you don’t want another command, you can do something like this:
CRhinoCommand::result CCommandPullCage::RunCommand(const CRhinoCommandContext& context)
{
bool bPullByNormal = false;
CRhinoGetOption go;
go.SetCommandPrompt(L"Pull by normal?");
go.SetDefaultString(L"No");
go.AcceptNothing();
int n_opt = go.AddCommandOption(RHCMDOPTNAME(L"No"));
int y_opt = go.AddCommandOption(RHCMDOPTNAME(L"Yes"));
CRhinoGet::result res = go.GetOption();
if (res == CRhinoGet::option)
{
const CRhinoCommandOption* option = go.Option();
if (nullptr == option)
return CRhinoCommand::failure;
if (n_opt == option->m_option_index)
bPullByNormal = false;
else if (y_opt == option->m_option_index)
bPullByNormal = true;
}
else if (res != CRhinoGet::string)
return CRhinoCommand::cancel;
if (bPullByNormal)
{
RhinoApp().Print(L"Pulling cage by normal.\n");
}
else
{
RhinoApp().Print(L"Pulling cage.\n");
}
return CRhinoCommand::success;
}
Then make two button macros like this:
PullCage Yes
PullCage No
– Dale
Thanks Dale. I’ll give that a try!
What if I wanted a numeric argument. such as “PullCage 0.025”. Do I have to have preset options?
This one ties into my next task of how do I avoid (for now) implementing rhino GUI dialog boxes