Macros and pre-selection


#1

I’m having a issue with the commands in my custom plugin when trying to use them in a macro: when I run a macro like this:

! _CreateSplashes _Distance 15 _Height 4

it works great if I don’t have any pre-selection. If I do have a pre-selection, I get a bunch of “Unknown command” messages for each one of the options I’m trying to set. My understanding is that, because of the pre-selection, my GetObject.Get is returning GetResult.Object right away, without setting the options first. What’s the best way around this (if there is any)? I’d like my commands’ options to be settable in a macro, just like the native commands are.


(Dale Fugier) #2

Well, you can always do this:

_SelNone
_CreateSplashes _Distance 15 _Height 4

Also, you object getter can tell you whether or not object were pre-selected. So you could check this an, if so, prompt for the options.

var go = new GetObject();
go.GetMultiple(1, 0);
if (go.CommandResult() == Result.Success)
{
  if (go.ObjectsWerePreselected)
  {
    // TODO: prompt for options here (too)
  }
}

– Dale


#3

I would like to void using _SelNone, it kind of defeats the purpose of preselection.

I did think of checking ObjectsWerePreselected in case of success, but how do I query for options here, once the command has been run? Do I loop GetString and switch to match my options? Or is there a better way of handling it? (I actually don’t even know if the loop idea makes any sense at all…)


(Dale Fugier) #4

Now you understand why most Rhino commands that prompt for objects do not prompt for options at the same time.

Here are a couple of options (no pun intended):

1.) Prompt for objects using GetObject.
2.) Prompt for distance using GetNumber.
3.) Prompt for height using GetNumber.

or

1.) Prompt for objects using GetObject.
2.) Prompt for distance and height using GetOption.

– D


#5

Dale,
Thank you very much for your help, I was able to get it to work perfectly! My solution ended up being like this

if (getObjectAction.CommandResult() == Result.Success)
{
	if (getObjectAction.ObjectsWerePreselected)
	{
		GetOption getOption = new GetOption();

		getOption.AddOptionDouble("Distance", ref optDistance, "Splash offset distance");
		getOption.AddOptionDouble("Height", ref optHeight, "Splash height");
		
		getOption.SetCommandPrompt("Select Objects");
		getOption.SetWaitDuration(1);
		
		while (getOption.Get() == GetResult.Option);

	}
}

The while ensures that all my options are correctly read, and of course can be used to check on the individual options if needed.