Hatching in Python in Grasshopper


#1

So in Grasshopper I am trying to create a custom script/component for creating Hatches. I am looking at the Rhino Common example for creating a hatch as blueprint. I would like to do it in Python but when I use the python example I get an error message out of the component "Solution exception:‘GrasshopperDocument’ object has no attribute ‘HatchPatterns’ ". But If I do with the C# component then it works. I am pretty new to the Rhino common stuff so don’t know all the intricacies. My lamens guess is it has to do something with the python using the scriptcontext.doc. in the example. Although don’t know for sure.


(Dale Fugier) #2

You might want to edit this topic and change the category from “Rhino Developer” to “Grasshopper” - you might get a quicker response…


(Steve Baer) #3

I don’t think switching the category is going to make much of a difference. I marked this topic as something I need to get back to since it is going to take a little digging into the code to figure out what the best approach is.


#4

Thanks Steve.


(Dale Fugier) #5

I only mentioned this because I am not sure @DavidRutten is monitoring this category…


(Steve Baer) #6

Sure, I get it. It’s just that a topic like this could be categorized at Scripting, Rhino Developer, or Grasshopper Developer.

I’m not sure what level there is for hatch support in GH, and I’m guessing that the ghpython document currently doesn’t have support for hatch patterns. Still need to sit down and try typing something up.


#7

@dale & @stevebaer I actually debated what category to put it under and was actually looking for a way to assign it to multiple categories. Can we do that?


(Steve Baer) #8

No, multiple categories are not supported in discourse. No matter where you put the topic, we’ll look at it and possibly even change the category if we think it ‘fits’ better in a different category. This is not something anyone should have to debate.


(Steve Baer) #9

I just tested writing a python script for GH to hatch a curve.

import Rhino
 
if (curve and curve.IsClosed and curve.IsPlanar()):
    hatches = Rhino.Geometry.Hatch.Create(curve, 0, 0, 1)

This script does create hatch geometry, but there is no preview in GH. I don’t think GH currently supports hatch geometry, but I could be mistaken. @DavidRutten is this correct?


Python rhinoscript AddText() not working
#10

Yes, but then you need something like this to get it to create the hatch in the Rhino file correct?

if Button == True:
    for hatch in hatches:
         scriptcontext.doc.Objects.AddHatch(hatch)

At least that is way it’s shown in the Rhino Common example.


(Steve Baer) #11

Yes, this is how it would be done to “bake” the hatches to the Rhino document.


#12

So I get this message

Runtime error (MissingMemberException): ‘CustomTable’ object has no attribute ‘add’

and when I step through the options/tips

scriptcontext.doc.Objects…

There isn’t an AddHatch().


(Steve Baer) #13

Use

Rhino.RhinoDoc.ActiveDoc.Objects.AddHatch(hatch)

instead of scriptcontext.doc


#14

Awesome that worked.

I also used the Rhino.RhinoDoc.ActiveDoc. get the hatch pattern index.

Thanks for the help.