Grasshopper

algorithmic modeling for Rhino

I am assuming that I need to add a GUID to the list of GUIDs in the following override. I am confused about how to do this. I've been doing some digging, and I cant find exactly what I need.

I have a list of text tags. How do i assign, or retrieve, the GUID for a list of tags in order to bake them? I've tried the following code, but it does not work. I have tried other variations of the coding, but I seem to be missing some fundamental concept here.

Dim tags as New List (of Rhino.Display.Text3d)

Public Overrides Sub BakeGeometry(doc As Rhino.RhinoDoc, att As Rhino.DocObjects.ObjectAttributes, obj_ids As List(Of Guid))
Dim g As Guid
g = tags.GetType.GUID
obj_ids.Add(g)
MyBase.BakeGeometry(doc, att, obj_ids)
End Sub

Views: 688

Replies to This Discussion

When you try to bake a component in Grasshopper, the method "BakeGeometry" is automatically called. the "List(Of Guid)" obj_ids is actually information that the method creates, rather than the required input to the method - it's information OUT, not IN. 

When BakeGeometry is called, this list gets populated by some other function within the method - usually something like RhinoDoc.Objects.AddText (or AddCurve or AddBrep etc). These functions return a Guid, which is then added to obj_ids.

VB's not my strong suit, but I think something like this would be a correct override to BakeGeometry:

Public Overrides Sub BakeGeometry(doc As Rhino.RhinoDoc, att As Rhino.DocObjects.ObjectAttributes, obj_ids As List(Of Guid))

For Each tag As Text3d In tags
Guid id = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(tags, att)

obj_ids.Add(id)
Next

End Sub

 

This assumes you've already populated tags as a list of Text3d in your SolveInstance. To do things properly, you should also do some things to avoid errors - checking that att isn't null, for instance, or that the Guid is a valid one. (AddText returns Guid.Empty if it was unable to add the object to the document.)

dude you are a life saver!

FYI variable declaration is a bit different

Guid id (c#)
Dim id as Guid (vb)

told you VB wasn't my strong suit :)

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