How to add hatches in AutoCAD so that they overlap each other?

  Kiến thức lập trình

I am using the Python language and the win32com.client library to add hatches to a drawing.

Here is the code that implements the creation of hatchings:

import win32com.client
import pythoncom

acad = win32com.client.Dispatch("AutoCAD.Application")
acadModel = acad.ActiveDocument.ModelSpace 

def APoint(x, y, z = 0):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))

def ADouble(xyz):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (xyz))

def variants(object):
    return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, (object))

out_loop = [acadModel.AddPolyline(ADouble([0,0,0,1000,0,0,1000,1000,0,0,1000,0,0,0,0]))]

hatch = acadModel.AddHatch(0, "HEX", True)
hatch.PatternScale = 20
hatch.AppendOuterLoop(variants(out_loop))
hatch.Evaluate()

hatch = acadModel.AddHatch(0, "ANSI31", True)
hatch.PatternScale = 10
hatch.AppendOuterLoop(variants(out_loop))
hatch.Evaluate()

The task is to find a solution to overlapping hatches on each other, which can be implemented using python. The desired result is shown on the right side of the picture.

pic

I can do this task manually in autocad using the Explode command to the first hatch and then add a second hatch. But I need to implement this using Python.

I was also advised a method where WipeOut and SuperHatch are used, but I still haven’t figured out how to implement this in code.

Maybe it need to modify the autocad scripts, with lisp or Autolisp. I don’t know.

LEAVE A COMMENT