Run command when object is clicked/selected

Hi,

Until now I’ve only created commands but is it also possible to let a command run when an object is clicked?
This is to automatically edit notes when an object is selected.

  • Jordy

Searching the same for if notes change it will export these to default.txt

There is an event in RhinoCommon, called RhinoDoc.SelectObjects.

When your plug-in loads, you can subscribe to this event. Each time an object is selected, the event is fired and you can respond with the necessary action. To run a command upon selection, it is easiest to use RhinoApp.RunScript(…) upon object selection.

as standard a command is summonded bij:

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

what should this be for RhinoDoc.SelectObjects?

Do you have an example?

You can holder an instance of this class in you plugin class.

Public Class DocUSer

Public Sub New()
    AddHandler Rhino.RhinoDoc.BeginOpenDocument, AddressOf wnBeginOpenDocument
    AddHandler Rhino.RhinoDoc.NewDocument, AddressOf wnNewDocument
End Sub

Public WithEvents Doc As Rhino.RhinoDoc
Private Sub OnRhinoObjectSelect(sender As Object, args As Rhino.DocObjects.RhinoObjectSelectionEventArgs) Handles Doc.SelectObjects
    For Each obj In args.RhinoObjects

'Do someting you like

    Next
End Sub
Private Sub wnNewDocument(sender As Object, args As Rhino.DocumentEventArgs)
    Me.Doc = args.Document
End Sub
Private Sub wnBeginOpenDocument(sender As Object, args As Rhino.DocumentOpenEventArgs)
    Me.Doc = args.Document
End Sub

End Class

Can’t get it too work somehow.
If I create a new vb code file and paste it in it should work?
I;ve just tested it when i select something it should msgbox(“Hi”) but nothing.

SOLVED:

I did this:

added this to New Sub()

AddHandler Rhino.RhinoDoc.SelectObjects, AddressOf RhinoSelectObjects

added this at the end of my file

    Private Sub RhinoSelectObjects(ByVal sender As Object, ByVal e As Rhino.DocObjects.RhinoObjectSelectionEventArgs)

        MsgBox("HI")

    End Sub

Thanks anyways Youngfe :slight_smile:

Found this for normal forms:

'Disable all event firing.
Application.EnableEvents = False

Does this exist in Rhino?

EDIT: It’s solved on another way.

hi,
maybe a late reply, but…
how did you create instance at plugin class then?

thanks

What are you trying to do? This post is a while ago and I can’t remember what the problem was then.
The plugin class is created when I create a new project. It’s called somenameplugin. What language are you programming?