Item Command Arguments

From The Foundry MODO SDK wiki
Revision as of 01:28, 28 February 2012 by Shf (Talk | contribs) (Created page with "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 o...")

(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 Object 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
	CLxUser_Item		 item;
	CLxUser_CommandService	 svcCmd;
	CLxUser_Command		 cmd;
	CLxUser_Attributes	 attr;
	CLxUser_ValueReference	 ref;

	// Create a new command.
	if (svcCmd.NewCommand (cmd, "item.draw")) {
		attr.set (cmd);
	
		// Set the integer 'mode' argument to 'add'.
		attr.SetInt (0, 1);

		// Set the &item argument.
		attr.ObjectRW (2, ref);
		ref.SetObject (item);

		// Execute the command.
		cmd.Execute (LXfCMD_EXEC_DEFAULT);
	}

Authoring Commands

You can also create a command utilizing a &item argument.

Declaring

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

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
	}