Hello, i create a script to add hatch but the problem it can’t detect list hatch automatically unless i open options and select hatch than click ok.
This happen also with other hatch components from other plugins
One “work around” is to use rs.HatchPatternNames() as the first thing in your code.
That will load the default patterns without going into options.
don’t forget to use scriptcontext when using rhinoscriptsyntax.
sc.doc = Rhino.RhinoDoc.ActiveDoc
hNames = rs.HatchPatternNames()
sc.doc = ghdoc
As far as I know, it is best practice to return the scriptcontext focus back to the grasshopper document.
In most cases, I subscribe to the “always use rhinocommon when working in ghpython” school of thought. (which eliminates the need for scriptcontext stuff in the first place). But, rhinoscriptsyntax certainly does have it’s place sometimes.
Perhaps something has changed in Rhino, but as a rule, (unless someone knows otherwise?), I would say you should always set the focus back to the ghdoc when your done with your rhinoscript operation.
I don’t want open a new thread since it is about the same component but a different problem;
when i click bake 4 duplicate hatches created, i don’t know why?
Can anyone please check the script and you are free to modify to make it more simple and better
add hatch.gh (9.8 KB)
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import rhinoscriptsyntax as rs
import Rhino as rh
import scriptcontext as sc
import Rhino.Geometry as rg
import math
class CreateHatch(component):
def RunScript(self,Curve,Hatch,Angle,Scale,Hatch_Color,Boundary_Color,Bake):
sc.doc = rh.RhinoDoc.ActiveDoc
rs.HatchPatternNames()
sc.doc = ghdoc
self.c1 = Hatch_Color
self.c2 = Boundary_Color
if not self.c1 : self.c1 = System.Drawing.Color.Black
else : self.c1
if not self.c2: self.c2 = System.Drawing.Color.Black
else : self.c2
self.c = Curve
self.n = Hatch
if not self.n : self.n = 0
else : self.n
self.r = Angle
if not self.r : self.r = 0
else : self.r
self.s = Scale
if not self.s : self.s = 1
else : self.s
self.bake = Bake
if not self.c: return
def DrawViewportMeshes(self,arg):
if not self.c: return
doc = rh.RhinoDoc.ActiveDoc
H = doc.ActiveDoc.HatchPatterns
hatch = rg.Hatch.Create(self.c,self.n,math.radians(self.r),self.s)
pip = arg.Display
rh.Display.DisplayPipeline.DrawHatch(pip,hatch[0],self.c1,self.c2)
if self.bake == True:
doc.Objects.AddHatch(hatch[0])
doc.Views.Redraw()
Problem solved; i use this
instead of
if self.bake == True:
doc.Objects.AddHatch(hatch[0])
doc.Views.Redraw()
Another problem
DisplayPipeline.DrawHatch show hatch of one curve; but rs.AddHatch bake them all with auto-detection of region
After baking:
Fixed; both solutions work , the first one work even hatch preview off and the second one need hatch preview on
I am trying to understand what does arg means in this occasion.
Is it something like operator overloading?
I cannot understand how the arg is being instantiated.
as far as I understood pip should be a DisplayPipeline, but as it is stated here:
You yourself cannot create a new pipeline, only Rhino can.
And apparently there should be initialized the whole DisplayPipeline chain, BoundingBox and DrawHatch.
But where is all of that happening? Inside pip which is arg? .Display is the BoundingBox??
Confusing =(((((
This is an old script; no need to use pip
def DrawViewportWires(self,arg):
hatch = rg.Hatch.Create(self.c,self.n,self.r2,self.s)
for i in hatch:
arg.Display.DrawHatch(i,self.c1,self.c2)
Thank you for your reply.
I still cannot understand where and how the “arg” is being instantiated.
If I understand correctly, the arg here is used to self-instantiate the DrawViewportWires function?
I am trying to recreate it in Procedural Mode, but unsuccessful
Can you share your script?
I don’t know about the details of arg or args but i use tools as they are.
Hi @anon39580149 ,
sorry for the delayed message, the war put it all off for later…
Basically I am trying to implement it for multiple input curves within multiple cycles (ListAccess).
I tried many things, ended up using sticky. I wanted to use sticky to check updates, in order to eliminate any hatch overlaps. However, this still isn’t working properly. Maybe there is an easier way to display multiple curves?
If I am not storing the hatches into the RhinoDoc, it displays only the last input curve.
And if I only add hatches to the RhinoDoc, without using sticky, it just bakes the hatches onto the canvas, without colors:
Perhaps you have already implemented something similar. I would be very happy if you could have a chance to take a glance on it.
Here is the code
multiCycleHatches.gh (14.5 KB)
I will check it later.
There is a hatch component use it, and baking hatch color is not available in Rhinocommon, you must ask the developers to add this feature
Thank you @anon39580149
I need to do it in Python, cannot use any other components
I don’t need to bake, only preview.
This approach works fine while running only one cycle (fine, except it bakes some of the hatches):
But while running multiple cycles, the DrawPreviewMeshes displays only the last cycle.