Get display component (Pattern Hatch) content via python code


I’m using a display component, (Display->Dimensions->Pattern Hatch) without any out gate:

I assume there is a field that contains the values of this component (in this case, lines) which can be accessed via code.

I prefer to use python and I tried to explore this component:

import rhinoscriptsyntax as rs
import Rhino as rh
import inspect

ghdoc = ghenv.Component.Attributes.Owner.OnPingDocument()
rhdoc = rh.RhinoDoc.ActiveDoc
hatch = [x for x in ghdoc.Objects if x.NickName == "PHatch"]

for prop in inspect.getmembers(type(hatch[-1]), lambda a:not(inspect.isroutine(a))):

for attr in inspect.getmembers(type(hatch[-1].Attributes), lambda a:not(inspect.isroutine(a))):

without any success to find the correct attribute and getting the content itself.

I’ll appreciate any help.

– Y

Mayde there is a better way to get the full list

import Grasshopper

ghdoc = ghenv.Component.Attributes.Owner.OnPingDocument()
objs = ghdoc.Objects 
hatch = [x for x in objs if x.Name == "Pattern Hatch"]

hatches = ["Solid","Single Line","Double Line",
"Triple Line","Dashed Line",
"Square Grid","Triangle Grid",
"Plus Grid", "Squares"]

ids = []
names = []
for i,h in enumerate(hatch):
    id = hatch[i].Params.Input[1].VolatileData[0][0]
    hname = hatches[int(id.ToString())]

Hi @anon39580149 !

Thanks for your answer.

Actually, I want access to the lines themselves, for example:

Is there anyway I can get them inside a GHPython component?


Do you want bake the hatch and add it to Rhino or explode it in Grasshopper?

I don’t think explode is possible but maybe you can access to all settings from inputs and recreate new hatch then you can control it

@anon39580149 No, I don’t want to bake them. I want to manipulate them inside a python component before baking.
I don’t think I got you - recreate new hatch how?

I assume it must be a way to get the content of a display component directly although there is no output channel, since these curves exist somewhere. Don’t you think so?

I don’t understand what you want exactly
You can simply create new hatches from the curves, why you need the hatches from this component? (8.2 KB)

Thanks again! @anon39580149

It’s hard to explain why I need them because it’s a huge project.

Maybe I’m not clear enough, I’ll try again - how can I get the pattern (the curves inside the bounderies) itself as curve/line objects?
In your gh file, for example, these curves:

I don’t need the hatch as an object or the input parameters (since I’m the one how feed them into the display component).
I’ll really appreciate that if you can find an answer.

I already answered, the python code extract exactly the hatch pattern

I’m sorry, I can’t see that.

Which one of the python component’s outputs can be treated as “curve” (not the bouderies)?

Did you open the file?

Of course

Check all outputs

I have already did:

I’m not an expert as you can see…can you please be more specific?

Maybe I didn’t understood you correctly but by “explode it in Grasshopper” you actually meant that I can get the curves inside the boundaries? same as baking to rhino->explode in rhino->select the curves in Grasshopper?

What is not clear?

check ‘geos’ please, it’s empty…or try to look at g[1], its an empty array of lines.

I re download your file:

any relevant dependencies?

Try this, you need to add import scriptcontext as sc
And use sc.doc instead of doc

import Rhino.Geometry as rg
import Rhino as rh
import rhinoscriptsyntax as rs
import ghpythonlib.treehelpers as th
import scriptcontext as sc

hatches = ["Solid","Single Line","Double Line",
"Triple Line","Dashed Line",
"Square Grid","Triangle Grid",
"Plus Grid", "Squares"]

def HatchInfo(hdata):
    sc.doc = rh.RhinoDoc.ActiveDoc
    Hp = sc.doc.ActiveDoc.HatchPatterns
    crvs = []
    geos = []
    for b in hdata.Params.Input[0].VolatileData[0]:
    p = hdata.Params.Input[1].VolatileData[0][0].Value
    s = hdata.Params.Input[2].VolatileData[0][0].Value
    a = hdata.Params.Input[3].VolatileData[0][0].Value
    hname = hatches[p]
    new = rg.Hatch.Create(crvs,p,a,s)
    for i,n in enumerate(new):
        g = rg.Hatch.CreateDisplayGeometry(n,Hp[p],1)
    geos = th.list_to_tree(geos)
    return crvs,p,s,a,hname,new,geos

crvs,pat,scale,angle,name,new,geos = HatchInfo(hatch)