Grasshopper

algorithmic modeling for Rhino

I'm working on a set of components to assist in large scale arena seating design. I'm having a problem with text. I'm using the code below (supplied by David) to display text values of geometric dimensions.

This code works fine in the GH VB component. It displays dimensions perfectly for any listed data (there are modifications to the code to associate text with lines, points, etc.). The problem is that when I transfer this same code into a script for a custom GHA component, the text appears, but all other geometry created by the component is invisible(until I bake). Also, the text does not bake. I think that it has something to do with the overrides. Somehow the overrides are causing only the text to appear.

Please help, if you can.

I can attache the VB proj if necessary.

Private Sub RunScript(ByVal C As Circle, ByRef A As Object)
If (runCount = 0) Then
tags = New List(Of Rhino.Display.Text3d)
box = BoundingBox.Empty
End If

If (Not C.IsValid) Then Return
If (C.Radius <= 0.0) Then Return

Dim tag As New Rhino.Display.Text3d(String.Format("{0:0}", C.Radius), C.Plane, C.Radius * 0.5)
tags.Add(tag)
box.Union(tag.BoundingBox)
End Sub

'
Private tags As List(Of Rhino.Display.Text3d)
Private box As BoundingBox

'Return a BoundingBox that contains all the geometry you are about to draw.
Public Overrides ReadOnly Property ClippingBox() As BoundingBox
Get
Return box
End Get
End Property

'Draw all wires and points in this method.
Public Overrides Sub DrawViewportWires(ByVal args As IGH_PreviewArgs)
If (tags Is Nothing) Then Return
If (owner.Attributes.Selected ) Then
For Each tag As Rhino.Display.Text3d In tags
args.Display.Draw3dText(tag, args.WireColour_Selected)
Next
Else
For Each tag As Rhino.Display.Text3d In tags
args.Display.Draw3dText(tag, args.WireColour)
Next
End If
End Sub
'

Views: 1393

Replies to This Discussion

Stuff is drawn inside DrawViewportWires, so when you override the method you short-circuit the default behaviour. Place a call to the base class to get that functionality back:

Public Overrides Sub DrawViewportWires(ByVal args As IGH_PreviewArgs)

  MyBase.DrawViewportWires(args)

  ...

 

Be sure to do the same for other methods you override in the preview such as ClippingBox.

Public Overrides ReadOnly Property ClippingBox() As BoundingBox
  Get

    Dim clipBox As BoundingBox = MyBase.ClippingBox
    clipBox.Union(box)

    Return clipBox
  End Get
End Property

 

Baking is a completely different thing from previewing. If you want to bake your text as well, you need to override the BakeGeometry(ByVal doc As RhinoDoc, ByVal att As ObjectAttributes, ByVal obj_ids As List(Of System.Guid)) method.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you, works great! I would like to post the component once complete.
"BakeGeometry(ByVal doc As RhinoDoc, ByVal att As ObjectAttributes, ByVal obj_ids As List(Of System.Guid))"

I am assuming that I need to add a GUID to the list of GUIDs in this 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 tags (as in the previous comments). How do i assign, or retrieve, the GUID for a list of tags? I've tried the following code, but it does not work.

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)
obj_ids.Add(ComponentGuid)
MyBase.BakeGeometry(doc, att, obj_ids)
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