Query Command Values example

From The Foundry MODO SDK wiki
Revision as of 19:45, 15 August 2013 by Jangell (Talk | contribs)

Jump to: navigation, search
# Need a command service object
cmd_svc = lx.service.Command()
# With that we can spawn an instance of the command we're interested in.
#  The first argument is pretty much always CTAG_NULL; the second is the
#  name of the command.
cmd = cmd_svc.Spawn(lx.symbol.iCTAG_NULL, 'item.name')
# We then pass the arguments for the command to 'QueryArgString()'.
# The second argument is the alert flags, which are usually 0 since you
#  rarely want alert dialogs opening when you query.
# The third argument is the argument string to be parsed.  The argument
#  marked with a '?' (in this case, "name') is the one that will be queried.
#  Since this is parsing an argument string, standard command string
#  parsing behaviors apply.
# The final argument is indicates if the string includes the command's
#  name or not; ours doesn't so we set it to 0 (false).
va, idx = cmd_svc.QueryArgString(cmd, 0, 'name:?', 0)
# The above gives us a value array object containing the queried value,
#  from which we can extract using the correct method for the argument
#  type as 'va' It also gives us the argument index (as 'idx') that was
#  queried (meaning, the one marked with the '?'), which is useful if we
#  want to execute the command with the queried value.  Furthermore,
#  any other arguments passed to QueryArgString() as the command
#  string will now be set as though you had called one of the Set...()
#  methods for it.
# Here we use GetString(), but you'll generally want to use whatever is
#  appropriate for this argument's datatype,
name = va.GetString(0)

See Also