Created
November 19, 2015 09:54
-
-
Save lukpazera/775a04088cac74a5399d to your computer and use it in GitHub Desktop.
An example function showing how to query command's argument from C++ MODO SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This function allows for querying a command argument. | |
* It's possible to set any other command's arguments first | |
* prior to the query. This is done by passing a map with | |
* argument name/value pairs. | |
*/ | |
bool queryCmdArg(const char* cmdName, const char* argName, std::map<std::string, CLxUser_Value>& otherArgs, CLxUser_ValueArray& valArray) | |
{ | |
CLxUser_CommandService cmdSrv; | |
CLxUser_Command cmd; | |
if ( ! cmdSrv.NewCommand (cmd, cmdName) ) { | |
return false; | |
} | |
CLxUser_Attributes cmdAttr; | |
cmdAttr.set (cmd); | |
// Set command arguments first, if any. | |
if ( ! otherArgs.empty() ) | |
{ | |
std::map<std::string, CLxUser_Value>::iterator iter; | |
for ( iter = otherArgs.begin(); iter != otherArgs.end(); ++iter ) { | |
int argIndex = cmdAttr.FindIndex (iter->first); | |
if ( argIndex >= 0 ) { | |
unsigned int valueType = iter->second.Type(); | |
if ( valueType == LXi_TYPE_INTEGER ) { | |
int value = 30; | |
iter->second.GetInt(&value); | |
cmdAttr.SetInt(argIndex, value); | |
} | |
else if ( valueType == LXi_TYPE_FLOAT ) { | |
double value; | |
iter->second.GetFlt(&value); | |
cmdAttr.SetFlt(argIndex, value); | |
} | |
else if ( valueType == LXi_TYPE_STRING ) { | |
std::string value; | |
iter->second.String(value); | |
cmdAttr.SetString (argIndex, value.c_str()); | |
} | |
} | |
} | |
} | |
int argIndex = cmdAttr.FindIndex (argName); | |
if ( ! cmdSrv.QueryIndex (cmd, argIndex, valArray) || ! valArray.Count() ) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment