Grasshopper

algorithmic modeling for Rhino

Hi,

 

Does anyone know if it's possible to output/display a text string at a specific location in 3d space from a custom component? I know a workaround would be to output a list of anchor locations for the text strings and another list containing the strings to be displayed. We'll then use the GH texttag3d to display this text.

 

It would be nice to reduce the number of outputs and components to do this. If anyone has any suggestions, please post them.

 

Thanks.

 

Kermin

Views: 451

Replies to This Discussion

Hi Kermin - 

 

You'll need to use the CustomDisplay class to display this text. 

 

private void RunScript(string Text, Plane Location, double Size, ref object A)  {

    if (m_display == null)      m_display = new Rhino.Display.CustomDisplay(true);
    m_display.Clear();

    m_display.AddText(Text, Location, Size);

  }


  //<Custom additional code>

   private Rhino.Display.CustomDisplay m_display;

  //</Custom additional code>

 


 

also, it might be advisable to include a boolean to clear the customdisplay - otherwise you can get stuck with all kinds of extra geometry floating around.

Hi Andrew,

Thanks for the tip. You are right about clearing out the custom display. Unfortunately, I'm not understanding how we cancall m_Display.dispose when grasshopper recalculates the solution.

 

It seems to me, I need to call ".dispose" method at every event of grasshopper recalculation otherwise, the previous display is "stuck". But this seems to be a chicken and egg thing since after recalculation, the previously declared custom display variable no longer exists.

 

Let me know if my understanding is wrong or if there's a simple way to fire off the ".dispose" upon recalculation.

 

Thanks.

 

Kermin

My understanding of this is limited, but I don't think you need to call .dispose on every recalculation. The point of declaring m_display outside of runscript is to have only one instance, so that we can clear its previous contents when we draw something new to it. David explains the nuances of CustomDisplay much better than I could in this thread: http://www.grasshopper3d.com/forum/topics/how-to-use-the-rhinodispl...

 

 

My solution, which never disposes m_display, is just to make all the code that draws something conditional on a boolean input - that way "clear" always happens on every refresh but drawing the text or other graphics depends on an exterior boolean toggle. Annoyingly, this means that if you leave this toggle set to draw and switch to another definition, the text remains visible, but if you return to the definition and set the toggle the other way it disappears. With CustomDisplay it is easy to get multiple copies of what you're trying to draw and be unable to get rid of them, and this is the only way I've found to avoid that entirely. 

 

If anyone has a better way of doing this I would love to hear 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