Custom Text Display in GHPython

Hi

I have checked the post by @AndersDeleuran, and it is wonderful.

Continuing the discussion from Text on display:

I was trying with the GHPython on custom display, and I found that the text is not aligned with point location. How to do that?

Thanks in advance.
Vijesh

2 Likes

I don’t have an answer regarding the point location but have you played around with text justification methods at all?

May be worth looking into

1 Like

Check this (i.e. docs) out, especially the middleJustified argument description.
Currently, in your script, it is set to False, which translates to the text being lower-left justified in terms of world coordinates. If you want to center it on the point, you need to make it True.

When in doubt, consult the documentation. :wink:

1 Like

I can’t quite remember what that code does, but self.point looks like a 2D point (i.e. a screen space point with X and Y being in pixels from the top left corner) made using the XY components of the input Point (i.e. a point in 3D space). So the text won’t show up on screen where the input Point is. Try using one of these overloads instead:

Edit: Yup, that was it:

1 Like

It is perfect, How do I do if I have a list of texts? When I placed the list of texts and Location Points in the same code it was not giving any results.

You can loop over the texts/points, like so:


200401_GHPython_DrawViewportWires_03.gh (10.9 KB)

3 Likes

Thank you very much. I also want to ask is that the texts are dynamically changing the height while zooming in and out, but we want a fixed height. Can we do that?

In that case you probably want to implement Draw3dText instead (using the camera frame), like so:


231113_DrawTexts3D_GHPython_00.gh (8.5 KB)

2 Likes

thank you very much.

1 Like