Command

References
public abstract class Command
Defines a base class for all commands. This class is abstract.

Constructors

Command

#
protected Command()
Default protected constructor. It only allows instantiation through sub-classing.

Properties

CommandContextHelpUrl

#
protected virtual string CommandContextHelpUrl { get; }
Gets the URL of the command contextual help. This is usually a location of a local CHM file.

The default implementation return an empty string.

EnglishName

#Since v5.0
public abstract string EnglishName { get; }
Gets the name of the command. This method is abstract.

HistoryReplayOnObjectAttributeChange

#Since v8.34
public bool HistoryReplayOnObjectAttributeChange { get; set; }
By default, object attribute changes do not trigger history replay. Set this property to true, typically in the command's constructor, if you want objects created with this command to trigger history replay when their attributes change.

Id

#Since v5.0
public virtual Guid Id { get; }
Gets the unique ID of this command. It is best to use a Guid attribute for each custom derived command class since this will keep the id consistent between sessions of Rhino GuidAttribute

LastCommandId

#Since v5.0
public static Guid LastCommandId { get; }
Gets the ID of the last commands.

LastCommandResult

#Since v5.0
public static Result LastCommandResult { get; }
Gets the result code of the last command.

LocalName

#Since v5.0
public virtual string LocalName { get; }
Gets the local name of the command.

PlugIn

#Since v5.0
public PlugIn PlugIn { get; }
Gets the plug-in where this commands is placed.

Settings

#Since v5.0
public PersistentSettings Settings { get; }
Gets the settings of the command.

Methods

DisplayHelp

#Since v5.0
public static void DisplayHelp(Guid commandId)
Displays help for a command.
commandId (Guid)A command ID.

GetCommandContextHelpUrl

#Since v8.18
public static string GetCommandContextHelpUrl(Guid commandId)
Returns a command's context help url.
commandId (Guid)A command ID.
The command's context url if provided.

GetCommandNames

#Since v5.0
public static string[] GetCommandNames(bool english, bool loaded)
Gets list of command names in Rhino. This list does not include Test, Alpha, or System commands.
english (bool)if true, retrieve the English name for every command. if false, retrieve the local name for every command.
loaded (bool)if true, only get names of currently loaded commands. if false, get names of all registered (may not be currently loaded) commands.
An array instance with command names. This array could be empty, but not null.

GetCommandStack

#Since v5.0
public static Guid[] GetCommandStack()
Determines if Rhino is currently running a command. Because Rhino allow for transparent commands (commands that can be run from inside of other commands), this method returns the total ids of active commands.
Ids of running commands or null if no commands are currently running. The "active" command is at the end of this list.

GetCommandStyle

#Since v9.0
public static Style GetCommandStyle(Guid commandId)
Returns a command's style flags.
commandId (Guid)A command ID.
The command's style flags, or Style.None if the command is not found.

GetMostRecentCommands

#Since v5.0
public static MostRecentCommandDescription[] GetMostRecentCommands()
Gets an array of most recent command descriptions.
An array of command descriptions.

InCommand

#Since v5.0
public static bool InCommand()
Determines if Rhino is currently running a command.
true if a command is currently running, false if no commands are currently running.

InScriptRunnerCommand

#Since v5.0
public static bool InScriptRunnerCommand()
This is a low level tool to determine if Rhino is currently running a script running command like "ReadCommandFile" or the RhinoScript plug-in's "RunScript".
true if a script running command is active.

IsCommand

#Since v5.0
public static bool IsCommand(string name)
Determines is a string is a command.
name (string)A string.
true if the string is a command.

IsValidCommandName

#Since v5.0
public static bool IsValidCommandName(string name)
Determines if a string is a valid command name.
name (string)A string.
true if the string is a valid command name.

LookupCommandId

#Since v5.0
public static Guid LookupCommandId(string name, bool searchForEnglishName)
Returns the ID of a command.
name (string)The name of the command.
searchForEnglishName (bool)true if the name is to searched in English. This ensures that a '_' is prepended to the name.
An of the command, or Guid.Empty on error.

LookupCommandName

#Since v5.0
public static string LookupCommandName(Guid commandId, bool englishName)
Returns the command name given a command ID.
commandId (Guid)A command ID.
englishName (bool)true if the requested command is in English.
The command name, or null on error.

OnHelp

#
protected virtual void OnHelp()
Is called when the user needs assistance with this command.

ReplayHistory

#
protected virtual bool ReplayHistory(ReplayHistoryData replayData)
Repeats an operation of a command.

In order to make this function work, you will likely need to grab the Result property that gives the list of input objects. Then, you will be able to replace these inputs by using one of the UpdateToX() methods of the ReplayHistoryResult.

You should NOT use any document AddX() or ReplaceX() functions, as they will break history.

replayData (ReplayHistoryData)The replay history information.
true if the operation succeeded.

The default implementation always returns false.

RunCommand

#
protected abstract Result RunCommand(RhinoDoc doc, RunMode mode)
Executes the command.
doc (RhinoDoc)The current document.
mode (RunMode)The command running mode.
The command result code.

RunProxyCommand

#Since v6.13
public static void RunProxyCommand(RunCommandDelegate commandCallback, RhinoDoc doc, object data)
Execute some code as if it were running in a command
commandCallback (Command.RunCommandDelegate)
doc (RhinoDoc)
data (object)optional extra data to pass to callback

Events

BeginCommand

#Since v5.0
public static event EventHandler<CommandEventArgs> BeginCommand
Called just before command.RunCommand().

EndCommand

#Since v5.0
public static event EventHandler<CommandEventArgs> EndCommand
Called immediately after command.RunCommand().

UndoRedo

#Since v5.0
public static event EventHandler<UndoRedoEventArgs> UndoRedo
Used to monitor Rhino's built in undo/redo support.