If you want to use a command that has an item argument, you will need to set the value of the argument from an item you hold.
Given the Attributes Interface from the command (or any attributes interface with a &item value), you first get the attribute as a value reference, then set the value to your item.
| CLxUser_[[Item Interface|Item]] item;
CLxUser_[[Attributes Interface|Attributes]] attr;
CLxUser_[[ValueReference Interface|ValueReference]] ref;
unsigned idxArg;
|
| attr.ObjectRW (idxArg, ref);
ref.SetObject (item);
|
This complete example shows executing a command with an item argument. First we create the item.draw command, get the attributes interface, then set the mode and item arguments, and finally execute it.
| CLxUser_[[Item Interface|Item]] item;
CLxUser_[[CommandService Interface|CommandService]] svcCmd;
CLxUser_[[Command Interface|Command]] cmd;
CLxUser_[[Attributes Interface|Attributes]] attr;
CLxUser_[[ValueReference Interface|ValueReference]] ref;
|
| if (svcCmd.NewCommand (cmd, "item.draw")) {
attr.set (cmd);
|
| attr.Set (attr.FindIndex ("mode"), 1); // 'add' mode
|
| attr.ObjectRW (attr.FindIndex ("item"), ref);
ref.SetObject (item);
|
| cmd.Execute (LXfCMD_EXEC_DEFAULT);
}
|
You can also create a command utilizing a &item argument.
If you’re using the CLxBasicCommmand helper class, then defining your argument is done in the constructor for the command.
| CMyCommand::CMyCommand ()
{
dyna_Add ("item", "&item");
}
|
Reading the item passed to a command, the index of the command’s &item argument is specified by ‘’idxArg’’.
| CLxUser_[[Item Interface|Item]] item;
CLxUser_[[Attributes Interface|Attributes]] attr;
CLxUser_ValueReference ref;
unsigned idxArg;
|
| if (dyna_Object (idxArg, ref) && ref.Get (item)) {
// do stuff with item
}
|