Grasshopper

algorithmic modeling for Rhino

Displaying text with location based on points using Python Scripted Components

Hi everyone,

I'd like to display text (as in floating text, not text dots) whose 'anchor'/location is based on a point, similar to the .gh file given by David Rutten in this post: How to display text. I'm attaching the same file here that David posted in that discussion in case anyone misses it.

However, I'd like to do it in Python. From what I've observed (intermediate Python coder, so I'm familiar with coding in Python, but not that great) there isn't an equivalent of the C# override for DrawViewportMeshes (correct me if I'm wrong!). How would I go about implementing the same thing in Python, completely as a script inside a component (no outside components needed except for input)? 

Example: 

Other things I'd like to do: the text should adjust for perspective, and the font and size can be changed. I don't need to bake the text or anything, but I may need to keep track of the text content and store it inside the User Data of the point should I bake it, because I am using the outputs of certain operations as inputs for others.

Much thanks in advance!

Views: 1093

Attachments:

Replies to This Discussion

While not exactly 1:1, I use the CustomDisplay class quite a lot to draw stuff from GHPython components. A neat trick to avoid displays lingering around, is to add them to the sticky dictionary (meaning you can always go in and clear them out if you close the GH document etc.).

I've given it a try based on a previous code of yours (attached below). One thing I'm wondering about is how to anchor the text to a point instead of a plane (so basically I'd need at least one vector). However, this would limit visibility, which leads to my next point. How do I code it such that it adjusts for perspective (it's still visible and readable even if I rotate the view). Any ideas?

P.S. One problem I've been running into is that when I try to turn the Preview off (this is crucial to what I'm building), Rhinoceros crashes. :( Any ideas why?

Attachments:

The CustomDisplay class is described in its documentation as "indeed, very basic" and does not have a camera aligned text object as such. That said, you could get the direction/plane of a viewport and use this to construct a Text3d that is aligned with its direction. This would be in world space and not screen space though (unlike the normal Grasshopper text tags). To have this update when rotating the view and such would however be quite involved (requiring events and quite some plumbing I suspect). I would probably consider other options (1: Using the options in CustomDisplay, 2: Outputting to the GH canvas and rendering using the default components or maybe Human, 3: Switching to a C# component assuming this has better options for you).

The crashing sounds quite weird, it's difficult to troubleshoot without a file though.

Edit: Just remembered that my colleague Paul has experience with accessing the DisplayPipeline from GHPython, might be worth hitting him up for advice.

I did some testing specifically on the crashing. It appears to crop up when certain commands (I was testing Viewport) are put into the function added to the Preview event. I'll post up a file here when I've documented it a bit more thoroughly.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service