you are not getting the calls to CalculateBoundingBox
and DrawOverlay
because they’re are defined inside of your __init__
method.
Bad indentation:
class DrawMeshesConduit(Rhino.Display.DisplayConduit):
def __init__(self, meshes):
super().__init__()
...
def CalculateBoundingBox(self, e):
...
def DrawOverlay(self, e):
...
Correct indentation:
class DrawMeshesConduit(Rhino.Display.DisplayConduit):
def __init__(self, meshes):
super().__init__()
...
def CalculateBoundingBox(self, e):
...
def DrawOverlay(self, e):
...
What is this grasshopper definition need to do? Grasshopper has its own display conduit for preview and if you implement a GH_ScriptInstance
you can use the method overrides to draw your preview code:
import Rhino
import Rhino.Geometry as RG
import Grasshopper
import System.Drawing as SD
import rhinoscriptsyntax as rs
class MyComponent(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, x, y):
self.center = RG.Point3d(5, 5, 5)
self.scale = y
return Rhino.Geometry.Sphere(self.center, x)
# Preview overrides
@property
def ClippingBox(self):
return RG.BoundingBox(RG.Point3d(0, 0, 0), RG.Point3d(5, 5, 5))
def DrawViewportWires(self, args):
args.Display.Draw2dLine(SD.Point(0, 0), SD.Point(100, 100), SD.Color.Red, 5)
def DrawViewportMeshes(self, args):
args.Display.DrawDirectionArrow(
self.center, RG.Vector3f(self.scale, 0.5, 0), SD.Color.Blue
)
args.Display.DrawDirectionArrow(
self.center, RG.Vector3f(0.5, self.scale, 0), SD.Color.Red
)
args.Display.DrawDirectionArrow(
self.center, RG.Vector3f(0, 1, self.scale), SD.Color.Green
)
args.Display.Draw2dText(
"Example Text", SD.Color.Yellow, RG.Point2d(30, 30), False, 16, "Consolas"
)
These buttons can help you setup the class implementation:
See this example:
test_gh_display.gh (6.6 KB)