Difference between revisions of "Query Command Values example"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 1: Line 1:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# need a command service object
+
# Need a command service object
 
cmd_svc = lx.service.Command()
 
cmd_svc = lx.service.Command()
# with that we can spawn an instance of the command we're interested in
+
 
 +
# 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')
 
cmd = cmd_svc.Spawn(lx.symbol.iCTAG_NULL, 'item.name')
# and pass that to the Command service's 'QueryArgString()' method
+
 
va, idx = cmd_svc.QueryArgString(cmd, 0, 'item.name ?', 1)
+
# We then pass the arguments for the command to 'QueryArgString()'.
# that gives us a value array object containing the queried value
+
# The second argument is the alert flags, which are usually 0 since you
# which we can extract using the correct method for the argument type.
+
#  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)
 
name = va.GetString(0)
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 14: Line 35:
 
[[Category: Python API]]
 
[[Category: Python API]]
 
[[Category: lx.service]]
 
[[Category: lx.service]]
 +
 +
== See Also ==
 +
* [[Command System: Querying]] explains how to query commands from the Command History.  The same basic syntax applies for any command string parsing, such as the string passed to QueryArgString().
 +
* [[ILxCommandService (index)#(143) SDK: ILxCommandService interface|QueryArgString() method]]
 +
* [[ILxCommandService (index)#(21) SDK: Declarations|Alert Flags]]
 +
* [[Command System]]

Revision as of 19:45, 15 August 2013

# 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