RunCommand

Hello,

Ther is any way to call a command without using RunScript?

What command are you looking for?

I want to call my own commands or othe rhino commands but I want to call a command not run a sdk function.

Couple of background questions.

  • You did make a plugin?

  • Did you drag and drop it into rhino?

  • If Yes your command should be usable like any other command. Typing it in the commandbar without Runscript.

  • If you want to call another command in your plugin you should use Rhinoapp.runscript("",True) Or make a Module and call it from there (From your normal command or the command that uses your other command).

Hope I did understand your question right because its still a bit vage.

That is the static method you should call to run any Rhino command, being it your own, or standard. A prefixed underscore (_) references the English name. A hyphen (-) should get rid of popups/forms.

If you mean to run a method from your own class library (.dll), then you can add a reference. Was that on the other hand what you were looking for?

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

I can call any command using RunScript I know that. I just want to know if there is another way to call a command.

The best way to execute any command, whether the command is in your plug-in or in Rhino, is to use Rhino.RhinoApp.RunScript. In doing this,features you expect to work, such as undo/redo, history, selection, etc., all work as you’d expect.

I’m assuming this is in the context of calling a command from some custom user interface. If that is the case, then you could package up your user interface state in a class and set that state on your command class, then call RunScript with your custom command. Your command could recognize that is has some state to work with and just use that information when running the command.

Thanks for the answer!

I’m hijacking this post a bit if you dont mind.

I see that @dale says that In doing this,features you expect to work, such as undo/redo, history, selection, etc., all work as you'd expect.. So i got a command that just rotates and put some layers on and off. I use a command like move then run my own command with layer and camera direction. If I undo then it will undo the layer / camera direction and not the move. Is it possible to not save that last command in the undo/redo part?

Yes you can use the command styles.

[System.Runtime.InteropServices.Guid("0000...")]
[CommandStyle(Style.DoNotRepeat|Style.NotUndoable)]
public class MyCommand : Command

Somehow Its not working. I can still undo them.
I’m using CommandStyle(Style.DoNotRepeat + Style.NotUndoable)

Command: _View_LeftAndRightLayer
Command: _View_Normal
Command: _Undo
Undoing View_Normal
Command: _Undo
Undoing View_LeftAndRightLayer

They still come back. I’ve also tried:

CommandStyle(Style.DoNotRepeat or Style.NotUndoable)
CommandStyle(Style.DoNotRepeat and Style.NotUndoable)
CommandStyle(Style.DoNotRepeat + Style.NotUndoable)

P.S. Only using CommandStyle(Style.NotUndoable) doesnt work either. @pascal is NotUndoable Bugged? I’m using VB.NET

I think undo/redo in command works just with geometry.

But I created a command like:

Imports System
Imports Rhino
Imports Rhino.Commands

Namespace MyProject1

    <System.Runtime.InteropServices.Guid("9b8adee5-e21b-40e8-a481-e792e89f8273"), CommandStyle(Style.NotUndoable)> _
    Public Class View_LeftLayer
        Inherits Command

        Shared _instance As View_LeftLayer 

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As View_LeftLayer
            Get
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
            Get
                Return "View_LeftLayer"
            End Get
        End Property

        Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result

            Definitions.LeftLayer.IsVisible = True 'Defined somewhere else (as layer)
            Definitions.LeftLayer.CommitChanges() 'Defined somewhere else (as layer)
            Definitions.RightLayer.IsVisible = False 'Defined somewhere else (as layer)
            Definitions.RightLayer.CommitChanges() 'Defined somewhere else (as layer)
            RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ZoomExtents()

            Return Result.Success

        End Function
    End Class
End Namespace

But if I use undo I can undo this command. Somehow. And i cant NotUndoable.

Sorry, you’re out of my league here I’m afraid messing with anything more than a script now and then… better wait for @stevebaer

-Pascal

Jordy, can you provide sample code that demonstrates undo not working? I need to be able to repeat it here…

Here is the code for Hide RightLayer and View LeftLayer

Imports System
Imports Rhino
Imports Rhino.Commands

Namespace MyProject1

    <System.Runtime.InteropServices.Guid("9b8adee5-e21b-40e8-a481-e792e89f8273"), CommandStyle(Style.NotUndoable And Style.DoNotRepeat)> _
    Public Class View_LeftLayer
        Inherits Command

        Shared _instance As View_LeftLayer 

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As View_LeftLayer
            Get
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
            Get
                Return "View_LeftLayer"
            End Get
        End Property

        Dim LeftLayer As DocObjects.Layer
        Dim RightLayer As DocObjects.Layer

        Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
            GetLayers()
            LeftLayer.IsVisible = True
            LeftLayer.CommitChanges()
            RightLayer.IsVisible = False
            RightLayer.CommitChanges()
            RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ZoomExtents()
            Return Result.Success
        End Function

        Public Sub GetLayers()
            For Each Layer As DocObjects.Layer In RhinoDoc.ActiveDoc.Layers
                If Layer.Name = "Left" Then
                    LeftLayer = Layer
                End If
                If Layer.Name = "Right" Then
                    RightLayer = Layer
                End If
            Next
        End Sub

    End Class
End Namespace

Here’s the code for RightLayer

Imports System
Imports Rhino
Imports Rhino.Commands

Namespace MyProject1

    <System.Runtime.InteropServices.Guid("d70097d1-31d9-4e3c-b488-c23fa1de9716"), CommandStyle(Style.NotUndoable And Style.DoNotRepeat)> _
    Public Class View_RightLayer
        Inherits Command

        Shared _instance As View_RightLayer

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As View_RightLayer
            Get
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
            Get
                Return "View_RightLayer"
            End Get
        End Property

        Dim LeftLayer As DocObjects.Layer
        Dim RightLayer As DocObjects.Layer

        Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
            GetLayers()
            LeftLayer.IsVisible = False
            LeftLayer.CommitChanges()
            RightLayer.IsVisible = True
            RightLayer.CommitChanges()
            RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ZoomExtents()
            Return Result.Success
        End Function

        Public Sub GetLayers()
            For Each Layer As DocObjects.Layer In RhinoDoc.ActiveDoc.Layers
                If Layer.Name = "Left" Then
                    LeftLayer = Layer
                End If
                If Layer.Name = "Right" Then
                    RightLayer = Layer
                End If
            Next
        End Sub

    End Class
End Namespace

And an example file with the layers and 2 objects.
ExampleFile.3dm (35.5 KB)

If you run the commands you will be able to “Undo” them. But as the commandstyle says Style.NotUndoable And Style.DoNotRepeat it shouldnt be undoable. It should just skip to the command before it.

This is what you wanted right @dale ?

Yes it is, and I am able to repeat the problem. I’ll report this as a bug, as it should work.