Skip to content

Commit

Permalink
fix(extra): Add viewport option to screen oriented test
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jul 4, 2024
1 parent 3a6db32 commit 8714343
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
Binary file modified ladybug_grasshopper/icon/LB Screen Oriented Text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion ladybug_grasshopper/json/LB_Screen_Oriented_Text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.7.1",
"version": "1.8.1",
"nickname": "Text2D",
"outputs": [
[]
Expand Down Expand Up @@ -32,6 +32,13 @@
"description": "An optional color to set the color of the text. If unspecified,\nit will be black.",
"type": "System.Drawing.Color",
"default": null
},
{
"access": "item",
"name": "viewport_",
"description": "Text for the name of the Rhino viewport to which the 2D screen-oriented\nlegend will be rendered. If unspecified, the 2D legend will be rendered\nin all viewports. Acceptable inputs include:\n-\nPerspective\nTop\nBottom\nLeft\nRight\nFront\nBack\nany view name that has been saved within the Rhino file",
"type": "System.Object",
"default": null
}
],
"subcategory": "4 :: Extra",
Expand Down
25 changes: 21 additions & 4 deletions ladybug_grasshopper/src/LB Screen Oriented Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
quotations). Default is "Arial".
_color_: An optional color to set the color of the text. If unspecified,
it will be black.
viewport_: Text for the name of the Rhino viewport to which the 2D screen-oriented
legend will be rendered. If unspecified, the 2D legend will be rendered
in all viewports. Acceptable inputs include:
-
Perspective
Top
Bottom
Left
Right
Front
Back
any view name that has been saved within the Rhino file
"""

from ghpythonlib.componentbase import executingcomponent as component
Expand All @@ -39,11 +51,12 @@ class MyComponent(component):
def __init__(self):
super(MyComponent,self).__init__()
self.text_2d_args = None
self.viewport = None

def RunScript(self, _text, leg_par2d_, _font_, _color_):
def RunScript(self, _text, leg_par2d_, _font_, _color_, viewport_):
ghenv.Component.Name = 'LB Screen Oriented Text'
ghenv.Component.NickName = 'Text2D'
ghenv.Component.Message = '1.7.1'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '4 :: Extra'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand Down Expand Up @@ -84,17 +97,21 @@ def RunScript(self, _text, leg_par2d_, _font_, _color_):
d_args = (
txt, _color_, rg.Point2d(or_x,or_y), False, _height, _font)
self.text_2d_args.append(d_args)
self.viewport = viewport_
else:
self.text_2d_args = None
self.viewport = None

def DrawViewportWires(self, args):
try:
if self.text_2d_args is not None:
# get the DisplayPipeline from the event arguments
display = args.Display
# render the 2D text from the arguments
for draw_args in self.text_2d_args:
display.Draw2dText(*draw_args)
if self.viewport is None or \
self.viewport.lower() == args.Viewport.Name.lower():
for draw_args in self.text_2d_args:
display.Draw2dText(*draw_args)
except Exception, e:
System.Windows.Forms.MessageBox.Show(str(e), "script error")

Expand Down
Binary file modified ladybug_grasshopper/user_objects/LB Screen Oriented Text.ghuser
Binary file not shown.
Binary file modified samples/visualization_set.gh
Binary file not shown.

0 comments on commit 8714343

Please sign in to comment.