Grasshopper

algorithmic modeling for Rhino


Hi.

Does anyone know, if and how it is possible to define the boundaries of a selection box in Vb.net?

*EDIT: My initial idea was to use the _SelWindow command. But i can't make it work:


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

    app.RunScript("-_SelWindow " & x.ToString & " " & y.ToString)

End Sub


I have a series of rectangular polyline curves, and i want my script to select all geometry within these polyline curves and export it to seperate dxf-files, one pr. polyline curve. I have finished the bake and export part, but the selection is proving difficult.

Regards
Thomas

Views: 1151

Replies to This Discussion

Hi Thomas,

I'd say that the neatest approach to this would be to iterate over the document objects, find the boundingbox for each one, find your selection boundary curves and see which objects are inside which boundaries. This can be done completely in code without resorting to running commands.

Are you using Grasshopper 0.7.X or 0.6.X?

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David

Thanks for the quick reply.

I agree, iterating over the document object would be the neatest way of doing it. But what about efficiency, i have 80 rectangles and within each about 100 geometries, of different types, both annotation objects and curves, won't it be slow to iterate through all these objects for each rectangle?

I use 0.6.X but i'm soon making the shift to 0.7.X
Only one way to find out. Rhino objects cache their boundingboxes so that part of it will be quite fast. This is a 2D problem only I suppose, so you only need 4 floating point comparisons to rule in a specific object for a specific boundary, and on average 2 comparisons to rule it out.

I have to go out for a bit now, but I can write something when I get back. I'm not entirely sure how Grasshopper fits into all of this just yet, it seems to be a pure Rhino task.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
I'm also out for the weekend shortly, but i would greatly appreciate you writing something, or just pointing me in the right direction. I haven't tried iterating through the document, but i remember having seen examples of it here on the forum and the bounding tests are easy enough.

What i receive is geometry which has been nested onto raw plates, some 3rd party CAD-nester is being used for packing most plates onto raw wood plates, which go into the CNC mill. So i just get the geometry and need a quick way to export typically 80+ plates to seperate files. So this is a pure Rhino question but im hoping to move the nesting into Grasshopper, making the whole workflow in Grasshopper. Unroll'ing and naming, and creating holes in the plates is already done in Grasshopper.
I wrote a file, but you won't be able to run it until I release the next version.

Here's the script contents:
Private Sub RunScript(ByVal regions As List(Of Box), ByVal files As List(Of String), ByRef A As Object)
   If (regions.Count <> files.Count) Then
     Print("You must supply equal numbers of regions and filenames")
     Return
   End If

   Dim boxes As New List(Of BoundingBox)
   For Each b As Box In regions
     boxes.Add(b.BoundingBox)
   Next

   'Iterate over all regions and filenames
   For i As Int32 = 0 To files.Count - 1
     doc.Objects.UnselectAll()
     Dim obj_count As Int32 = 0

     For Each obj As Rhino.DocObjects.RhinoObject In doc.Objects
       Dim objbox As BoundingBox = obj.Geometry.GetBoundingBox(True)
       If (IsInRegion(boxes(i), objbox)) Then
         obj.Select(True)
         obj_count += 1
       End If
     Next

     Print("{0} objects exported to {1}", obj_count, files(i))

     If (obj_count > 0) Then
       Dim export_dir As String = IO.Path.GetDirectoryName(files(i))
       If (Not IO.Directory.Exists(export_dir)) Then
         IO.Directory.CreateDirectory(export_dir)
       End If

       Rhino.RhinoApp.RunScript(String.Format("-_Export ""{0}"" _Enter", files(i)), False)
     End If
   Next
End Sub

'
Private Function IsInRegion(ByVal reg As BoundingBox, ByVal box As BoundingBox) As Boolean
   If (box.Max.X < reg.Min.X ) Then Return False
   If (box.Max.Y < reg.Min.Y ) Then Return False
   If (box.Min.X > reg.Max.X ) Then Return False
   If (box.Min.Y > reg.Max.Y ) Then Return False

   Return True
End Function


--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
Super. Looking forward to trying it, when will you release the next version?

Another quick thought, would it be possible to use Galapagos to create a definition that packs triangular curves within a rectangular boundary?
I'm already overdue on the next release. Sometime tomorrow though, no point in me fixing things without anybody benefiting from it.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
I tried it, it works perfect.

Thanks

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service