hatch with polyline

hatch with polyline

Anonymous
Not applicable
826 Views
4 Replies
Message 1 of 5

hatch with polyline

Anonymous
Not applicable
I am trying to hatch a box and the code would not work. Am I doing something wrong???

Sub hatchTestlala()

' Define the hatch
Dim hatchObj As AcadHatch
Dim patternName As String
Dim PatternType As Long
Dim bAssociativity As Boolean
' Define the hatch
patternName = "SOLID"
PatternType = 0
bAssociativity = True

' Create the associative Hatch object in model space
Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)

Dim PL(0 To 14)

PL(0) = 1
PL(1) = 1
PL(2) = 0

PL(3) = 1
PL(4) = 5
PL(5) = 0

PL(6) = 5
PL(7) = 5
PL(8) = 0

PL(9) = 5
PL(10) = 1
PL(11) = 0

PL(12) = 1
PL(13) = 1
PL(14) = 0

Dim outerLoop(0 To 0) As AcadEntity
Set outerLoop(0) = ThisDrawing.ModelSpace.AddPolyline(PL)

hatchObj.AppendOuterLoop (outerLoop)
hatchObj.Evaluate
End Sub
0 Likes
827 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
From the help file:
WARNING! Once the Hatch object has been created, you must append the outer
loop to the Hatch object for it to become a valid AutoCAD object. If you
attempt any operation other than calling the AppendOuterLoop method, AutoCAD
will enter an unpredictable state.

So create your pline BEFORE creating the hatch.

Jeff

wrote in message news:5067708@discussion.autodesk.com...
I am trying to hatch a box and the code would not work. Am I doing something
wrong???
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thank you Jeff,

The problem actualy was --> Dim PL(0 To 14) As Double

-J
0 Likes
Message 4 of 5

Anonymous
Not applicable
juno,

This is a sample from 12/5/05 that Jeff helped me with. might want to look
at that post as well.
thanks Jeff

John Coon

I would suggest the Solid Hatch option. Trying to fill an irregular shape
with basic solids will result in multiple objects that will be difficult to
maintain.
Once you have your pline:
Dim objHatch as AcadHatch
Set objPline =
ThisDrawing.ModelSpace.AddLightWeightPolyline(approachpoints2)
objPline.Closed = True
Set objHatch = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined,
"SOLID", True)
Set arrLoop(0) = objPline
objHatch.AppendOuterLoop arrLoop
objHatch.Evaluate









wrote in message news:5067708@discussion.autodesk.com...
I am trying to hatch a box and the code would not work. Am I doing something
wrong???

Sub hatchTestlala()

' Define the hatch
Dim hatchObj As AcadHatch
Dim patternName As String
Dim PatternType As Long
Dim bAssociativity As Boolean
' Define the hatch
patternName = "SOLID"
PatternType = 0
bAssociativity = True

' Create the associative Hatch object in model space
Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName,
bAssociativity)

Dim PL(0 To 14)

PL(0) = 1
PL(1) = 1
PL(2) = 0

PL(3) = 1
PL(4) = 5
PL(5) = 0

PL(6) = 5
PL(7) = 5
PL(8) = 0

PL(9) = 5
PL(10) = 1
PL(11) = 0

PL(12) = 1
PL(13) = 1
PL(14) = 0

Dim outerLoop(0 To 0) As AcadEntity
Set outerLoop(0) = ThisDrawing.ModelSpace.AddPolyline(PL)

hatchObj.AppendOuterLoop (outerLoop)
hatchObj.Evaluate
End Sub
0 Likes
Message 5 of 5

Anonymous
Not applicable
What they mean by that is not to call any method/properties FROM THE HATCH OBJECT before you call the appendouterloop or InsertLoopAt method.....
0 Likes