Grasshopper

algorithmic modeling for Rhino

Hi I am working on athoer Visual Studio VB project. I want to recreate a custom baking component, which inputs the geometry, layers names and colors from gh and bakes the objects on appropriate layers with colours.

It works in Vb, but when i try implementing it in visual studio there appear to be a problem. I cannot use the Goo type into the RhinoObject.Add method- it tells me that Goo is not RhinoObject.

In gh vbscript it worked. Looks like i miss some conversion/transition from Goo to RhinoObject?

Views: 1823

Replies to This Discussion

Code please.

pManager.AddGeometryParameter("Object", "O", "Object to bake", GH_ParamAccess.item)

pManager.AddColourParameter("Colour", "C", " Objects Colour", GH_ParamAccess.item, Drawing.Color.Black)

Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)

Dim geo As Grasshopper.Kernel.Types.IGH_GeometricGoo = Nothing

Grasshopper.Kernel.GH_Convert.ToGeometryBase(geo)

If Not (DA.GetData(0, geo)) Then Exit Sub

Dim color As Drawing.Color = Drawing.Color.Black
If (Not DA.GetData(1, color)) Then Return


Dim att As New Rhino.DocObjects.ObjectAttributes()

Dim doc As Rhino.RhinoDoc = Rhino.RhinoDoc.ActiveDoc
Dim layer_index As Integer = doc.Layers.Find(Name, True)

If (layer_index < 0) Then
layer_index = doc.Layers.Add(Name, color)
End If


att.LayerIndex = layer_index


att.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
att.ObjectColor = color

Rhino.RhinoDoc.ActiveDoc.Objects.Add(geo, att)

End Sub

Hi Aleksander,

The Objects.Add(...) method only accept Rhino object, but what you gave it is a Grasshopper geometry object. That was why it complained.

Anyway. The way to do it is to read in the input data as a IGH_BakeAwareData object (not as IGH_GemetricGoo object). The IGH_BakeAwareData object will have a BakeGeometry method that add the geometry to the Rhino world.

Dim geo as IGH_BakeWareData = Nothing

If Not (DA.GetData(0, geo)) Then Exit Sub

Dim att As New Rhino.DocObjects.ObjectAttributes()

Dim doc As Rhino.RhinoDoc = Rhino.RhinoDoc.ActiveDoc

...

Dim guid As Guid;

geo.BakeGeometry(doc, att, guid)

 

That's a good approach, you can also tty the GH_Convert.ToGeometryBase() method to convert various types of data into Rhino.Geometry.GeometryBase types.

Longs appropach works.

David --> but the problem is casting from GeometryBase to RhinoObject.

Ehhhh. Shifting from just vb scripting in gh into visual studio environment provided more syntax problem that I expected. Maybe you have some advice what to read to gain a solid foundation ?

If you download the Grasshopper SDK (from the help menu in the main Grasshopper windows) you can find some good beginner's tutorials and a comprehensive documentation of the Grasshopper API library, including classes and types defined by Grasshopper such as IGH_GeometricGoo, GH_Convert, GH_Mesh, GH_Point, etc...

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