Grasshopper

algorithmic modeling for Rhino

I am trying to create a VB node that will bake a closed Brep and then export the baked Rhino geometry to an IGES file. Right now, I am just trying to make the bake part of the node, but I cannot seem to get it to work.

Here is the code I'm using: (hull is the Brep, BakeOrNot is a boolean toggle)

 

  Private Sub RunScript(ByVal Hull As Object, ByVal BakeOrNot As Object, ByRef Results As Object)

    Dim doc As MRhinoDocument
    Dim obj_inst As IRhinoObject
    Dim obj_guid As System.Guid
    Dim att As IRhinoObjectAttributes

    Results = CType(Results, String)

    Dim ghBrep As New Grasshopper.Kernel.Types.GH_Brep

    ghBrep = Hull

    If BakeOrNot = True Then
      ghBrep.BakeGeometry(doc, att, obj_guid)
      Results = "Geometry has been baked!"
    End If

    Results = "Geometry failed to bake"
  End Sub

 

The error I get says:

Type 'MRhinoDocument' is not defined.

 

Does anyone have any thoughts on how to make this work?

Views: 1133

Replies to This Discussion

Hi dorvieto,

 

MRhinoDocument, IRhinoObject and IRhinoObjectAttributes are all types in the old SDK. They don't exist in RhinoCommon, or rather, they have different names now.

 

You'll need something like this (untested):

 

If (Not BakeOrNot) Then Return

Dim ghBrep As New Grasshopper.Kernel.Types.GH_Brep(Hull)

Dim id As Guid

If (ghBrep.BakeGeometry(doc, Nothing, id)) Then

  Results = "Geometry has been baked with id: " & id.ToString()

Else

  Results = "Geometry failed to bake"
End If

 

 

But you don't have to use GH_Brep at all, since you already have the Rhino.Geometry.Brep you can get away with this:

 

If (Not BakeOrNot) Then Return

Dim id As Guid = doc.Objects.AddBrep(hull)

If (id = Guid.Empty) Then

  Results = "Bake failed"

Else

  Results = "Bake succeeded"

End If

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I am now trying to bake mutiple sets of curves. Will code like that posted above work for lists of curves also? I have had trouble making it work with the existing code that I have. Any suggestions?

If you have a list of shapes you'll need to iterate over the list and bake the shapes individually.

 

Dim ids As New List(Of Guid)

For Each shape As Brep in hulls

  ids.Add(doc.Objects.AddBrep(hull))

Next

Results = ids

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Hi David-

I'm using the above code, but I'd like to delete the object after adding it (part of an animation, using SS of rhino viewport). I can't figure out how to delete the object. Here is code, not much changed from above:

Private Sub RunScript(ByVal path As String, ByVal geo As Brep, ByVal bakeOrNot As Object, ByVal results As Object, ByRef A As Object)
    If (Not bakeOrNot) Then Return

    Dim id As Guid = doc.Objects.AddBrep(geo)
    

    If (id = Guid.Empty) Then

      results = "Bake failed"

    Else

      results = "Bake succeeded"
      'doc.Objects.Delete(?What goes here? I can't delete id, can I?)



    End If
  End Sub

Thanks,

Matt

Nevermind, just realized I wasn't giving doc.Objects.Delete the second argument (the boolean). duh

Can someone explain what's going wrong here?

The following code take a screenshot at a specified interval. I'm using it to capture kangaroo animations. I'd like to use the new "Pen" display mode. It's probably not the most elegant solution, but the code works for the older display modes (shaded, ghosted, etc.), but when I set the display mode to Pen, the .png only contains the background of the viewport, without the geometry.

Thoughts?

Private Sub RunScript(ByVal path As String, ByVal geo As Brep, ByVal bakeOrNot As Object, ByVal results As Object, ByVal count As Integer, ByRef A As Object)
    If (Not bakeOrNot) Then Return

    Dim id As Guid = doc.Objects.AddBrep(geo)


    If (id = Guid.Empty) Then

      results = "Bake failed"

    Else

      Dim view As Rhino.Display.RhinoView = doc.Views.ActiveView
      view.Redraw
      Dim mode As Rhino.Display.DisplayModeDescription = Rhino.Display.DisplayModeDescription.FindByName("Pen")
      Dim ss As Bitmap = view.CaptureToBitmap(mode)
      ss.Save("C:\Users\mswaidan\Desktop\Test\" & count & ".png")
      doc.Objects.Delete(id, False)

      results = "Bake succeeded"

    End If
  End Sub

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