Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Last active October 27, 2015 08:47
Show Gist options
  • Save lukpazera/b0f894115b400787806d to your computer and use it in GitHub Desktop.
Save lukpazera/b0f894115b400787806d to your computer and use it in GitHub Desktop.
Snippet showing how to read user value via C++ MODO SDK.
/* To read user value we spawn a new user value command.
* Then, we are using the attributes interface set to the command
* to set command's first argument to the name of the user value
* that we want to read.
* Next we obtain the index the of "value" argument so we can query
* command for this argument and store user value's value in the value array.
* The final step is to read the value from value array and put it
* inside value int variable. In this case we know it's an int
* so we go with GetInt() directly. If you do not know value's type
* you can get it using .Type() method on the ValueArray interface.
*
* Similar code can be used to query any command. Spawn command first,
* then set all the arguments that need to be set for the query to return
* result you are after and finally query the command for the value.
*/
CLxUser_CommandService cmdSrv;
CLxUser_Command userValCmd;
int value = 0;
if (cmdSrv.NewCommand (userValCmd, "user.value")) {
CLxUser_Attributes cmdAttr;
CLxLoc_ValueArray valArray;
cmdAttr.set (userValCmd);
cmdAttr.SetString (0, "myUserValueName");
int valueArgIndex = cmdAttr.FindIndex ("value");
if (cmdSrv.QueryIndex (userValCmd, valueArgIndex, valArray)) {
if (valArray.Count() > 0) {
valArray.GetInt (0, &value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment