Item Command Arguments

From The Foundry MODO SDK wiki
Revision as of 00:04, 2 March 2012 by Shf (Talk | contribs) (Executing a command)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Commands may specify some arguments of the &item type. This is an item reference, and allows item IDs to be passed to commands directly on the command line. The value of the argument is not an item itself but actually a ValueReference which may contain a reference to an item.

Using Commands

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.

Setting an item argument

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		 item;
	CLxUser_Attributes	 attr;
	CLxUser_ValueReference	 ref;
	unsigned		 idxArg;

	attr.ObjectRW (idxArg, ref);
	ref.SetObject (item);
Executing a command

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		 item;
	CLxUser_CommandService	 svcCmd;
	CLxUser_Command		 cmd;
	CLxUser_Attributes	 attr;
	CLxUser_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);

Authoring Commands

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			 item;
	CLxUser_Attributes		 attr;
	CLxUser_ValueReference		 ref;
	unsigned		 idxArg;

	if (dyna_Object (idxArg, ref) && ref.Get (item)) {
		// do stuff with item