Clipping box does not work in custom preview component with python 3?

Hello,

Been trying to get this to work. So the python component has no input or output and draws a custom mesh. It needs to set a ClippingBox, but it has no affect with python 3 script.
The same thing works fine with C#.
In the image the mesh is visible as the C# providing the clippingbox like a a crutch. As soon as the Py3 is alone or the C# preview off, the mesh is not drawn.
Same problem on mac and windows.

Would be grateful for any help. Even confirming if it works or not elsewhere.

Here is the python code:

"""Grasshopper Script"""
import System
import Rhino
import Grasshopper

import rhinoscriptsyntax as rs

class MyComponent(Grasshopper.Kernel.GH_ScriptInstance):
    def RunScript(self, x, y):
        b = 100
        self.bb = Rhino.Geometry.BoundingBox(-b,-b,-b, b, b, b)

        return #self.ClippingBox.GetCorners()

    # Preview overrides
    @property
    def ClippingBox(self):
        return self.bb

    def DrawViewportWires(self, args):
        pass

    def DrawViewportMeshes(self, args: Grasshopper.Kernel.IGH_PreviewArgs):
        box = Rhino.Geometry.BoundingBox(-10,-10,-10,10,10,10)
        mesh = Rhino.Geometry.Mesh.CreateFromBox(box, 2, 2, 2)
        color = System.Drawing.Color.AliceBlue

        args.Display.DrawMeshWires(mesh, color, 6)

Try using this bounding box method instead and/or adding the IsPreviewCapable method:

1 Like

Thank you, Anders!
I have actually followed your examples and tried different ways. Haven’t found a single one that works on my setup(s) right now.

I have tried to use the IsPreviewCapable also.

I don’t think there could be much of a difference in how I initiate the BoundingBox, but I have also tired different methods and scopes. Lookin in the debugger I see that it is nicely available before return.

I am wondering if it could be bug in current release. Mine is (8.15.25019.13002, 2025-01-19 on mac)

Something like this appears to work on my system (Rhino 8, 8.16.25028.13001 on PC):


250207_DrawMesh_CPython_00.gh (3.5 KB)

Yes. Thanks!
I have now come to a similar resolution.
So the following syntax (as it comes with the script template and is stated in the docs) does not work (currently):

@property
def ClippingBox (self):
        return Rhino.Geometry.BoundingBox(-10,-10,-10,10,10,10)

It has to be

def get_ClippingBox(self):
        return Rhino.Geometry.BoundingBox(-10,-10,-10,10,10,10)

IsPreviewCapable seems to be irrelevant. Returning True or False seems to have no effect in any situation.

The component still needs to have at least one output even if it does not return.

1 Like

Indeed, looks like another bug. In GhPython one can implement it to draw without any input/output parameters:

I also tried in C# script.
And it has not effect there either. It also needs at least one output to be able to have a preview.
Seems to be something in how the new script component handles / allows the overrides.

I just remembered that we didn’t notify @eirannejad about this issue. He probably want to have a look :point_up:

1 Like

Weird. That is supposed to work. I can confirm it does not work when ClippingBox is decorated as @property. Created this YT and will get that fixed:

RH-86112 ClippingBox does not work as property getter

1 Like

Ugh I had completely forgotten about this. So in pythonnet there is a different property decorator for when a python class needs to override property of its base dotnet class:

import clr

# ...

    @clr.clrproperty(type(Rhino.Geometry.BoundingBox))
    def ClippingBox(self):
        return self.mesh.GetBoundingBox(False)

It is mostly because the decorator needs to know the Type since that is not available with pythons internal @property. The above snippet works.

I either have to fix python 3 so it puts get_ClippingBox in the code for now instead of using @property OR use this clr.clrproperty decorator

:thinking:

Until I can put my surgery gloves on and get into the bowels of Pythonnet.

RH-86112 is fixed in Rhino 8 Service Release 18 Release Candidate