Grasshopper

algorithmic modeling for Rhino

Hi all,

 

I'm wondering if it's possible to update real-time in Grasshopper a set of points that are defined in Rhino?

 

I'm working on a Voronoi system at the moment and want to be able to deselect point and regenerate the solution. The ideal would be:

 

- Have a set of points fully defined within Rhino

- Have a point component in Grasshopper

- Select all the points in Rhino and Grasshopper detects accordingly

- Deselect one point in Rhino and Grasshopper detects accordingly and recalculates

- Can reselect that point or continue to deselect points

 

I know Kangaroo uses a timer switch but I can't see how to implement it in this situation. When bringing points from Rhino to Grasshopper, I always right-click in the Grasshopper window and choose "set multiple points". I can't see how to do this automatically.

 

I have a basic knowledge of vb.net but only so far as using it for loops and conditions.

 

Z

Views: 1397

Replies to This Discussion

This requires handling of Rhino selection events, which I currently don't do. I tried writing a small script, but it's clear that either I made a mistake or the Deselection events are currently not properly handled in Rhino.

 

Create a new VB component and paste the following code into the RunScript subroutine:

 

Private Sub RunScript(ByVal x As Object, ByRef A As Object)

  AssignHandlers()   

  Dim points As New List(Of Point3d)   

    For Each ro As DocObjects.RhinoObject In doc.Objects.GetSelectedObjects(False, False)     

      If (ro Is Nothing) Then Continue For     

      If (ro.ObjectType = DocObjects.ObjectType.Point ) Then       

        points.Add(DirectCast(ro.Geometry, Rhino.Geometry.Point).Location)     

      End If   

    Next   

  A = points

End Sub

 

then paste the following code into the <Custom additional code> section:

 

Private Sub DestroyHandlers()   

  RemoveHandler RhinoDoc.SelectObjects, AddressOf RhinoSelectObjects   

  RemoveHandler RhinoDoc.DeselectObjects, AddressOf RhinoSelectObjects

End Sub 

 

Private Sub AssignHandlers()   

  DestroyHandlers()   

  AddHandler RhinoDoc.SelectObjects, AddressOf RhinoSelectObjects   

  AddHandler RhinoDoc.DeselectObjects, AddressOf RhinoSelectObjects 

End Sub


Private Sub RhinoSelectObjects(ByVal sender As Object, _

                   ByVal e As DocObjects.RhinoObjectSelectionEventArgs)   

  If (owner.OnPingDocument() Is Nothing) Then     

    DestroyHandlers()     

    Return   

  End If   

  owner.ExpireSolution(True) 

End Sub 

 

 

It seems to work with selecting objects, but not with deselecting them. Also, when you drag the points around, you get Selection events (and thus new solutions) for every single point.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Fantastic!

 

For me, it works for selection, deselection and moving. I'm running v0.8.0010 if that might make any difference.

 

Just when I think I'm coming to grips with Grasshopper, I see the VB code like above and realise I've only scratched the surface!

 

Thank you,

Z

Are you doing this on Rhino5? That might explain the difference.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

No. Rhino4 & Win7.

I've found one bug (not really), which may be the same as you found earlier.

 

If I've selected a group of points and click off them, Rhino deselects them but Grasshopper still registers them. However, when I deselect using the control button, everything can be deselected.

 

Perhaps Rhino sees the clicking off the points as different to a 'deselection' - maybe a 'selection of nothing'. I might be completely wrong with this though.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service