Query Command Values example

Querying the item.name command

item.name’s name argument can be queried to get the names of the currently selected items.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# by Gwynne Reddck
# 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.  The 0 indicates that we're
#  getting the first value in the array.  item.name will return an array
#  with the names of all of the currently selected items, so we have to
#  tell it which one we want.
name = va.GetString(0)

Querying the pref.value for a color

The pref.value command is used to set and get the values of many preferences in the application. Not all prefs use pref.value; some use custom command instead, but all are displayed in the Preferences forms and represent some global option.

pref.value’s first argument is the preference we want to query or set, and the second argument is the value of the preference. The datatype of the second argument is defined by the preferences specified in the first. In this example, the color.wireframe preference is queried, which is defined as a color datatype. We choose to parse the value as a string, which is in the form of ‘’<nowiki>[R G B]</nowiki>’’, where the color components are floating point numbers.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Pick the colors from the preferences
# by David Ballesteros

# The command string that would be typed into the command history is "pref.value color.wireframe ?".
#   We're going to be a bit more verbose and use "pref.value name:color.wireframe value:?".

# First we need to get the command service
cmd_svc = lx.service.Command()

# Next we spawn the pref.value command.
cmd = cmd_svc.Spawn(lx.symbol.iCTAG_NULL, 'pref.value')

# We pass the arguments without the command name, marking the argument we want to query the
#  value of with a question mark.  As with the other example the second argument (flags) is 0 so
#  that no dialogs will open on failure, and the last argument is 0 (includCmd) indicating that the
#  argument string does not include the command's name.
# The returned values are a value array containing all of the queried values, which in this case
#  will only be a single value, and the index of the argument that was queried.
va, idx = cmd_svc.QueryArgString(cmd, 0, 'name:color.wireframe value:?', 0)

# We then get the value from the array as a string, and split it using the Python string split() method.
#  This just separates the string at the spaces, returning the components as an array.  Since we want
#  it as floats, we use map() to convert the result of split() to a float array,
rgblist = map(float, va.GetString(0).split())

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

  • ILxCommandService (index)#(21) SDK: Declarations

  • Command System