Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Created June 15, 2020 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukpazera/1c86843e18416294401aac6b3e14d1f9 to your computer and use it in GitHub Desktop.
Save lukpazera/1c86843e18416294401aac6b3e14d1f9 to your computer and use it in GitHub Desktop.
This snippet compares two methods of getting user value from MODO SDK. They give the same result but watch out for getting value via the ScriptSys service - it is MUCH slower, especially in MODO 14.1.
/*
* The first method is by using user.value command.
* This seems like indirect way compared to direct API call but it is actually WAY faster.
* Especially as of MODO 14.1 release.
* Use this one to get user 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, "userValueName");
int valueArgIndex = cmdAttr.FindIndex("value");
if (cmdSrv.QueryIndex(userValCmd, valueArgIndex, valArray)) {
if (valArray.Count() > 0) {
valArray.GetInt(0, &value);
}
}
}
/*
* This is nice and compact but it's SLOW!!!
* You won't notice with single calls, that's fine but with many calls the slowdown will be very very apparent.
*/
CLxUser_ScriptSysService scriptSysService;
CLxUser_UserValue listenValue;
if (!scriptSysService.UserValueLookup("userValueName", listenValue)) {
return false;
}
int value = 0;
listenValue.GetInt(&value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment