Skip to content

Instantly share code, notes, and snippets.

@mattcox
Last active July 12, 2018 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcox/5933732 to your computer and use it in GitHub Desktop.
Save mattcox/5933732 to your computer and use it in GitHub Desktop.
Demonstrates how to spawn another command from a command plugin. This will create a new command with a single argument called "mask", the mask argument will be passed to the material.new command to create a new material mask.This should only be used in the context of a command plugin.
#include <lx_plugin.hpp>
#include <lxu_command.hpp>
/*
* The server name is the name of the command that is used to run the command
* in modo. The argument name is the name of the argument that will define the
* material mask.
*/
#define SERVER_NAME "command.demo"
#define ARGUMENT_NAME "mask"
/*
* Define the command class.
*/
class Command :
public CLxBasicCommand
{
public:
Command ()
{
dyna_Add (ARGUMENT_NAME, LXsTYPE_STRING);
}
int
basic_CmdFlags () LXx_OVERRIDE
{
return LXfCMD_MODEL | LXfCMD_UNDO;
}
void
cmd_Execute (
unsigned int flags) LXx_OVERRIDE
{
std::string mask, command;
if (!dyna_IsSet (0))
return;
attr_GetString (0, mask);
command = std::string ("material.new {" + mask + "} true false");
if (LXx_OK (mCmdSvc.ExecuteArgString (-1, LXiCTAG_NULL, command.c_str ())))
{
// New material created. Do something with it.
}
}
static LXtTagInfoDesc descInfo[];
private:
CLxUser_CommandService mCmdSvc;
};
LXtTagInfoDesc Command::descInfo[] =
{
{ 0 }
};
/*
* Initialize the servers.
*/
void initialize ()
{
CLxGenericPolymorph *srv = new CLxPolymorph <Command>;
srv->AddInterface (new CLxIfc_Command <Command>);
srv->AddInterface (new CLxIfc_Attributes <Command>);
srv->AddInterface (new CLxIfc_AttributesUI <Command>);
srv->AddInterface (new CLxIfc_StaticDesc <Command>);
lx::AddServer (SERVER_NAME, srv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment