通過Hacth對象可以對圖元進(jìn)行填充,可以使用CBD自帶的圖案,或者使用外部圖庫中的圖案或者自定義臨時(shí)填充。創(chuàng)建Hatch對象并將其添加到ModelSpace集合,該函數(shù)需三個(gè)參數(shù)。以下代碼繪制一個(gè)Circle對象并創(chuàng)建填充。
Sub drawfilledcircle()
Dim hatchobject As AcadHatch
Dim outercircle(0) As AcadCircle
Dim center As Variant
Dim radius As Double
With ThisDrawing.Utility
center = .GetPoint(, "Click the position for the center.")
radius = .GetDistance(center, "Enter the radius.")
End With
Set outercircle(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
outercircle(0).color = acYellow
outercircle(0).Update
Set hatchobject = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined, "SOLID", True)
hatchobject.AppendInnerLoop (outercircle)
hatchobject.Evaluate
hatchobject.Update
End Sub
代碼完。
第一行聲明繪制填充圓的函數(shù),定義AcadCircle和AcadHatch對象,繪制圓形對其進(jìn)行填充。
AddHatch對象需要三個(gè)參數(shù),第一個(gè)是PatternType常數(shù)參數(shù),具有三個(gè)值:acHatchPatternTypePredefined,acHatchPatternTypeUserDefined,acHatchPatternTypeCustomfined,第二個(gè)參數(shù)指定填充圖元名稱,第三個(gè)參數(shù)指定填充是否關(guān)聯(lián)到邊界圖元,如果為false,填充不與邊界圖元相關(guān),若為true則填充隨圖元同時(shí)變化。