Grasshopper

algorithmic modeling for Rhino

I apologize if baking questions are a bit numerous, but after searching around I'm still having a little difficulty.

I have input a list of objects of different types into a VB script component. They are currently in a list of GeometryBase.
I want to loop through each of the items in the list and "bake" it into the document.

How should I handle the variety of geometry types?

Should I use the GetType() method to create a filter, using AddBrepObject, AddCurveObject, and so on based on the GetType() result?
If so, any recommendations on creating a quick conversion table based on the integer stored in the Type property?

Is there a way to add objects to the current document under some umbrella class, like GeometryBase, or without having to designate their geometry type?

Should I be using one of the BakeGeometry methods from the Grasshopper SDK? If so, would I need to recast the data into a new type? I'm a little fuzzy on the different Grasshopper namespaces.

Any help is greatly appreciated!

Views: 540

Replies to This Discussion

Actually, it looks like I can only get 4 unique results (Brep, Mesh, Curve, Point) from the ObjectType property of GeometryBase, after trying to input lots of different kinds of geometry from grasshopper. Which perfectly matches the number of different kinds of geometry I would need to designate to add each type to the ObjectTable. Looks pretty simple.
I separated the different geometry types, but the Point is giving me trouble.
Here's my code:
For j As Integer = 0 To obj_list.Count() - 1
Dim obj As GeometryBase = obj_list(j)
Dim t As Integer = obj.ObjectType
Dim o_id As Object = ""
If t = 16 Then
o_id = doc.Objects.AddBrep(obj, att)
ElseIf t = 32 Then
o_id = doc.Objects.AddMesh(obj, att)
ElseIf t = 1 Then
o_id = doc.Objects.AddPoint(obj, att)
ElseIf t = 4 Then
o_id = doc.Objects.AddCurve(obj, att)
Else
print("I'm not sure what kind of geometry is coming in the input. Try turning it into a Point, Curve, Mesh, or Brep before the input.")
Return
End If


and here's the error returned:
Error: Overload resolution failed because no accessible 'AddPoint' can be called with these arguments.
this is the line it refers to:
o_id = doc.Objects.AddPoint(obj, att)
Hi Benjamin,

I've been spending a little time to update the previous RenderAnimation (posed here - that internally has also to bake objects). So far I've only added methods for Breps and Meshes, but it should not be too hard to finish it. I've opted to keep it in a legacy components as the Materials in RhinoCommon need a little more properties.

- Giulio
___________________
giulio@mcneel.com
McNeel Europe, Barcelona
Attachments:
Additionally, as a comment to your code: in RhinoCommon you can use the standard .Net type checking and casting

If TypeOf x Is Brep Then
'...
End If

AddPoint(Point3d, Attributes) is not working above because Point3d is a ValueType (structure). The type that inherits from GeometryBase is Rhino.Geometry.Point. So, the line that is not compiling above will work if modified to:

o_id = doc.Objects.AddPoint(DirectCast(obj, Rhino.Geometry.Point).Location, att)
I hope that the attached file is helpful,

- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
Attachments:
Thank you Giulio! It now works perfectly, and your comments were very helpful.
I used the example you provided in simpleBake.ghx because it was the cleanest and simplest.

Much appreciation,

Ben
I tried to finish more of the methods, but was quickly stumped by some of the class differences in the RhinoObjects namespace.

This VBscript component I'm working on will export a rhino file with baked grasshopper geometry on designated layers. Combined with an Import VBscript component (which is already done), it allows you to batch process Rhino files using Grasshopper. It's what we used for the Local Code project, but I'm just trying to clean it up before I share it.

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