Grasshopper

algorithmic modeling for Rhino

Hy Guys,


last weekend I was working around with a little Programm I made, which searches randomly for possilble GH Objects to connect with other ones ...

For Example: If I want to know which (randomly choosen) GH Object could connect to (for example)  "Plane Components" (from the Category Vector, SubCategory Plane) it tells me, that "Evaluate Box" (from the Category Surface, SubCategory Analysis) would be a possibility. It searches for the needed Inputs and then randomly returns a GH Object which provides the Type of needed Input in his Output.

Now it's programmed with three Textboxes, where I have to type the Names of Category, SubCategory and the Object itself.

I would like to do it just with Mouseclicks: I just want to click on a Button in the prog and then just click on a Object on the Canvas and the Category, SubCategory and Name should appear in the Programm.

Does anyone have an Idea for this ??

Greets Alex

Views: 1063

Replies to This Discussion

The Data Viewer window does something akin to this I think. It either allows you to click-drag to find a specific parameter or it watches for all canvas Clicks.

There's no 'getter' mechanism in Grasshopper though, so you cannot ask the user to pick a component. It is however possible to watch for all clicks.

You can handle the DocumentObjectMouseDown event on GH_Canvas which is raised whenever someone clicks on an object. Let me know if you need further info.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hello David,

I was searching for the Data Viewer and I've found him, but I don't thing that this is the thing, that I've been searching for. I don't think that I can use this in my script.

I'm sorry for my noob questions, but how can I use the DocumentObjectMouseDown event in my VB script ?

Wouldn't this event be handled from the form rather than the script component?

You need to add a handler to that event. In order to do this you must create a function somewhere that has the correct signature, and then you assign that handler to the event.

Private Sub ObjectMouseDownHandler(ByVal sender As Object, ByVal e As GUI.GH_CanvasObjectMouseDownEventArgs)
  'Use the arguments (e) to update your form here.
End Sub

Then add a handler to it, I recommend doing this in the Load event of the form. Then in Unload or FormClosing or something remove then handler again.

AddHandler Grasshopper.Instances.ActiveCanvas.DocumentObjectMouseDown, AddressOf ObjectMouseDownHandler

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Good Morning Guys (especially David ;-))

I tested around a bit with my tiny know how about programming and the DocumentObjectMouseDown event, and I'm sorry but I just don't get it working.

I've added a txt file with my codesample which just should write the Text "TEST" into a label in my form whenever the canvas is clicked in grasshopper.

I'm happy for any kind of help.

Thx for your time

Alex

Attachments:

This works for me, Form with a label called LabelName:

 

Private Sub EventTestForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  AddHandler Instances.ActiveCanvas.DocumentObjectMouseDown, AddressOf ObjectMouseDown
End Sub


Private Sub EventTestForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
  RemoveHandler Instances.ActiveCanvas.DocumentObjectMouseDown, AddressOf ObjectMouseDown
End Sub


Private Sub ObjectMouseDown(ByVal sender As Object, ByVal e As GH_CanvasObjectMouseDownEventArgs)
  LabelName.Text = e.Object.Object.Name
End Sub

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sorry, doesn't work for me.


I also cannot exit the debugged application because of the FormClosed Part.

I don't get the ObjectName into the Label

Good morning,

After testing and trying a little bit I think that it has something to do with the Handler. I think that he gets stucked there ...

Alex

When you say not working, you mean there's an error, a compiler problem, or...?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sorry for my unprecise statement.
When I click start debugging in visual studio, there are no errors. Visual Studio starts the programm but then i can't do anything. When i do the '-stuff in the line, where the addhandler part is my code (sorry don't know how it is called in english) the programm works.
When i use an other addhandler code, for example keydown, the programm also works.

Hopes this helps

Again, "...but then i can't do anything." and "When i do the '-stuff in the line,..." is not really helpful because I don't know what it means exactly. You'll either need to use the English terminology or post screenshots/video of what you're seeing/doing.

 

If there are no compiler errors/warnings and no runtime exceptions, then please put breakpoints on the AddHandler instruction and inside the ObjectMouseDown() method to see if they both get called.

 

You could also post some compilable source that you think ought to work so I can test it here.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Imports Grasshopper
Imports Grasshopper.GUI
Imports Grasshopper.Kernel

Public Class EventTestForm

    Private Sub EventTestForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Grasshopper.Instances.ActiveCanvas.DocumentObjectMouseDown, AddressOf ObjectMouseDown
    End Sub

    Private Sub EventTestForm_FormClosed(sender As Object, e As EventArgs) Handles Me.FormClosed
        RemoveHandler Grasshopper.Instances.ActiveCanvas.DocumentObjectMouseDown, AddressOf ObjectMouseDown
    End Sub

    Private Sub ObjectMouseDown(ByVal sender As Object, ByVal e As GH_CanvasObjectMouseDownEventArgs)
        'Use the arguments (e) to update your form here
        LabelName.Text = e.Object.Object.Name
    End Sub

End Class

This is my complete Visual Studio 2012 VB Script (it's the same, that you posted a a few posts before)

Form with a Label called LabelName

When I debug it in Visual Studio, there are no errors.

But I can't close it (red x in the right upper corner) of the Form (Rectangle 1) and the LabelName.Text also not changes, as I am clicking on an Grasshopper Object (Rectangle 2)

Attachments:

I can't see a mistake in the code, when do you display this form? How does it tie in to your GHA project?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service