新規画層を作成し、色と線種プロパティをこの画層に割り当てることができます。
個々の画層は、Layers コレクションの一部です。Add メソッドを使用すると、新規画層を作成し、それを Layers コレクションに追加できます。
画層を作成するときに、その画層に名前を割り当てることができます。作成後に画層名を変更するには、Name プロパティを使用します。画層名は半角 31 文字までで、文字、数字、特殊文字のドル記号($)、ハイフン(-)、およびアンダースコア(_)を使用できます。 ただし、画層名に空白は使用できません。
次のコードは、円と新しい画層を作成します。新しい画層の色として赤を割り当てます。円は画層に割り当てられ、円の色はそれに応じて変わります。
Sub Ch4_NewLayer()
' Create a circle
Dim circleObj As AcadCircle
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 2: center(1) = 2: center(2) = 0
radius = 1
Set circleObj = ThisDrawing.ModelSpace.AddCircle(center, radius)
' Create a color object
Dim col As New AcadAcCmColor
col.ColorMethod = AutoCAD.acColorMethodForeground
' Set the layer to the color
Dim layColor As AcadAcCmColor
Set layColor = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & _
Left(AcadApplication.Version, 2))
Call layColor.SetRGB(122, 199, 25)
ThisDrawing.ActiveLayer.TrueColor = layColor
col.ColorMethod = AutoCAD.acColorMethodByLayer
' Assign the circle the color "ByLayer" so
' that the circle will automatically pick
' up the color of the layer on which it resides
circleObj.Color = acByLayer
circleObj.Update
End Sub