Color Property (ActiveX)

Specifies the color of an object or layer.

Supported platforms: Windows only

Signature

VBA:

object.Color
object

Type: All drawing objects, Group, Layer, MLeaderLeader, SubDMeshEdge, SubDMeshFace, SubDMeshVertex, SubEntity, SubEntSolidEdge, SubEntSolidFace, SubEntSolidNode, SubEntSolidVertex

The objects this property applies to.

Property Value

Read-only: No (except for the Group object which is write-only)

Type: acColor enum

The default color designation is acByLayer. Use a color index number from 0 to 256, or one of the constants listed here:

Remarks

This property is obsolete for most drawing objects and will be removed in a future version accordingly. When using this property, colors can be set and read as numeric index values ranging from 0 to 256. Constants are provided for the standard seven colors, as well as for the BYBLOCK and BYLAYER designations.

If you use acByBlock, AutoCAD draws new objects in the default color (white or black, depending on your configuration) until they are grouped into the block. When the block is inserted in the drawing, the objects in the block inherit the current setting of the color property.

If you use acByLayer, new objects assume the color of the layer upon which they are drawn. The value acByLayer is not valid for a Layer object.

Examples

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))
)