Grasshopper

algorithmic modeling for Rhino

Hi,
What is the necessary inputs to bake an object to the current document?

If I understand this correctly, we 

1. Cast a geometry to the GH type
2. Use the xxx.BakeGeometry method to bake it to the current open file

What settings do we need to assign to CurrentDoc and CurrentAtt? Do these automatically default to something workable?

Dim TestLine As New GH_Line
            TestLine.CastFrom(LineList.Item(0))
            Dim IsTestLineValid As Boolean = TestLine.IsValid

Dim CurrentDoc As Rhino.RhinoDoc
Dim CurrentAtt As Rhino.DocObjects.ObjectAttributes
Dim ObjectID As New System.Guid

CurrentAtt.LayerIndex = 0
TestLine.BakeGeometry(CurrentDoc, CurrentAtt, ObjectID)


Thanks.

kermin

Views: 543

Replies to This Discussion

Hi Kermin,

you don't technically need to supply the Attributes, though I'd recommend you cook up some defaults.

And you don't have to use the Grasshopper methods to add objects to the document, you can also call RhinoDoc.Objects.AddXXXX() methods. This may be much simpler if you know what kind of geometry you're dealing with (curves, say, or meshes, instead of just some form of geometry.)

One important thing to realize is that GH_Goo (or IGH_Goo, or IGH_GeometricGoo) do not provide the methods for baking. BakeGeometry() is defined in the IGH_BakeAwareData interface (indeed, this interface defines nothing else), but a lot of classes that implement IGH_Goo also implement IGH_BakeAwareData.

Thus if you have an instance of IGH_Goo or IGH_GeometricGoo you still won't be able to bake it until you cast it to IGH_BakeAwareData.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Could anyone show just a very brief code example of casting IGH_Goo or IGH_GeometricGoo to IGH_BakeAwareData?

thanks!
Hi Benjamin,

using TryCast (also DirectCast will be ok here):

Dim att As New Rhino.DocObjects.ObjectAttributes 'from somewhere

If TypeOf x Is IGH_BakeAwareData Then
  Dim g As New Guid
  Dim bk As IGH_BakeAwareData = TryCast(x, IGH_BakeAwareData)
  If(bk.BakeGeometry(doc, att, g)) Then
    Print("Baking succeeded")
  End If
End If


- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
Thanks Giulio!
So in this case x is IGH_GeometricGoo, and
If TypeOf x Is IGH_BakeAwareData Then
checks if the geometry being handled is a type that inherits from IGH_BakeAwareData?
Yes, you cannot bake a number.

- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
... unless it is pi
:)
Made my day.

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

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