Clipping Planes with Hatches in Grasshopper

ghpython
(Chris Hanley) #1

Below is a WIP of a way to use/manipulate a clipping plane, and apply a hatch fill . Most of the code is from things I have posted before, (I will provide links below). It also uses the Human Plugin, (which I use all the freaking time!), for some line weight display . Also, maybe the make2d components can already do this?

It uses 4 custom components:
1 - Retrieve hatch patterns from active Rhino Doc (Human has this)
2 - Apply those hatch patterns to some boundary curves
3 - Apply a material from the active Rhino Doc to preview
4 - Create 1 clipping plane

Reference:
Material with GHPython - Code Example

Hatch with GHPython - Code Example

Clipping Planes in GH - Discussion


Here is the current example code for the clipping plane from GHPython. (Type hint for Plane input set to Plane, Type hint for F, set to Boolean)
NOTE: this is off the cuff/bespoke code, and is just a working test. mileage may vary.

import Rhino
import scriptcontext as sc
import Grasshopper

if F and Plane:
    Plane.Flip()
try:
    # Check if exists in sticky, if not, Add the cutting plane, add GUID to the sticky dict, delete object
    if "cplaneID" not in sc.sticky: 
        AVGuid = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewportID
        NewClipPlane = Rhino.RhinoDoc.ActiveDoc.Objects.AddClippingPlane(Plane, 25, 25, AVGuid)
        sc.sticky["cplaneID"] = NewClipPlane
        Rhino.RhinoDoc.ActiveDoc.Objects.Delete(Rhino.RhinoDoc.ActiveDoc.Objects.FindId(sc.sticky["cplaneID"]))
    # If it does exsist, delete it and create a new one each time this component updates
    else:
        Rhino.RhinoDoc.ActiveDoc.Objects.Delete(Rhino.RhinoDoc.ActiveDoc.Objects.FindId(sc.sticky["cplaneID"]))
        AVGuid = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewportID
        NewClipPlane = Rhino.RhinoDoc.ActiveDoc.Objects.AddClippingPlane(Plane, 1, 1, AVGuid)
        sc.sticky["cplaneID"] = NewClipPlane
        print sc.sticky["cplaneID"]
except Exception, ex:
    ghRunTimeMsgLevel = Grasshopper.Kernel.GH_RuntimeMessageLevel
    ghenv.Component.AddRuntimeMessage(ghRunTimeMsgLevel.Warning,str(ex))

a = Plane
1 Like