オブジェクトまたは画層の色を指定します。
サポートされているプラットフォーム: Windows のみ
VBA:
object.Color
タイプ: すべての図形オブジェクト、Group、Layer、MLeaderLeader、SubDMeshEdge、SubDMeshFace、SubDMeshVertex、SubEntity、SubEntSolidEdge、SubEntSolidFace、SubEntSolidNode、SubEntSolidVertex
このプロパティが適用されるオブジェクト。
読み込み専用: いいえ(書き込み専用の Group オブジェクトを除く)
タイプ: acColor 列挙型
既定の色指定は acByLayer です。0 から 256 のカラー インデックス番号か、以下の定数の 1 つを使用します。
このプロパティはほとんどの図形オブジェクトに対して旧式であるため、将来のバージョンでは除去される予定です。このプロパティを使用すると、色を設定し、0 ~ 256 の範囲の数値のインデックス値として読み込むことができます。標準の 7 色だけでなく、ByBlock と ByLayer の名前にも、定数があります。
acByBlock を使用すると、AutoCAD は新しいオブジェクトを作成する際、ブロックにグループ化するまでは既定の色(環境設定により白または黒)を使用します。ブロックを図面に挿入すると、ブロック内のオブジェクトは現在の色のプロパティを継承します。
acByLayer を使用すると、新しいオブジェクトには画層の色が適用されます。acByLayer という値は、Layer オブジェクトには有効でありません。
VBA:
Sub Example_Color()
' This example creates a polyline and colors it red.
' It then displays the current color setting for the polyline.
Dim plineObj As AcadPolyline
Dim currentcolor As Variant
' Create Polyline
Dim points(8) As Double
points(0) = 3: points(1) = 7: points(2) = 0
points(3) = 9: points(4) = 2: points(5) = 0
points(6) = 3: points(7) = 5: points(8) = 0
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
' First set the color of the object to Red
plineObj.Color = acRed
ThisDrawing.Regen (True)
' Now retrieve and display the Color property
currentcolor = plineObj.Color
' Translate the color from a number into text
If currentcolor = 256 Then
currentcolor = "By Layer"
Else
currentcolor = Choose(currentcolor + 1, "By Block", "Red", "Yellow", "Green", "Cyan", "Blue", "Magenta", "White")
End If
' Display
MsgBox "The Polyline color is: " & currentcolor, vbInformation, "Color Example"
End Sub
Visual LISP:
(vl-load-com)
(defun c:Example_Color()
;; This example creates a polyline and colors it red.
;; It then displays the current color setting for the polyline.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Create Polyline
(setq points (vlax-make-safearray vlax-vbDouble '(0 . 8)))
(vlax-safearray-fill points '(3 7 0
9 2 0
3 5 0
)
)
(setq modelSpace (vla-get-ModelSpace doc))
(setq plineObj (vla-AddPolyline modelSpace points))
;; First set the color of the object to Red
(vla-put-Color plineObj acRed)
(vla-Regen doc :vlax-true)
;; Now retrieve and display the Color property
(setq currentcolor (vla-get-Color plineObj))
;; Translate the color from a number into text
(if (= currentcolor 256)
(setq currentcolor "ByLayer")
(setq currentcolor (cond
((= currentcolor 257) "ByBlock")
((= currentcolor 1) "Red")
((= currentcolor 2) "Yellow")
((= currentcolor 3) "Green")
((= currentcolor 4) "Cyan")
((= currentcolor 5) "Blue")
((= currentcolor 6) "Magenta")
((= currentcolor 7) "White/Black")
("Other")
))
)
;; Display
(alert (strcat "The Polyline color is: " currentcolor))
)