Autocad Color Object


The autocad color property was superseded about 2004 with the color object. The object.color property still exists, but, “This property is obsolete for most drawing objects and will be removed in a future version…”

Autocad Color Property (ActiveX)

While the color property of an autocad entity can be changed easily (for now) and simply with object.color = number, the number is limited to integers 0 to 255, the Autocad Color Index, or ACI. Each of these numbers represents an RGB value. Its not immediately obvious (to me) what the numbering scheme is, it must be an old standard. Also the RGB values change depending on the autocad background color. For instance color 53 can be RGB (204,204,102) for a Black background and (165,165,82) for a White background. A similar but brighter color for the darker background.

If you wish to examine the RGB values of the ACI, its not too difficult to write out the list to an excel spreadsheet, using the new color object and its property ColorIndex.

 Sub testwriteRGB()
      Dim i As Integer
      Dim color As AcadAcCmColor
      Dim i_r As Integer, i_g As Integer, i_b As Integer

      Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.20")

      'this array for writing list to excel
      Dim pt4() As Double
      ReDim pt4(1 To 255, 1 To 4)

      For i = 1 To 255
        color.ColorIndex = i
        pt4(i, 1) = color.ColorIndex
        pt4(i, 2) =
        pt4(i, 3) =
        pt4(i, 4) =
      Next i

    Call display_pt4(pt4)
End Sub

 Sub display_pt4(pt4() As Double)
 'we are expecting a 4-wide array of variable length
  If UBound(pt4, 2) <> 4 Then
        MsgBox "array not 4-wide"
        Exit Sub
  End If

    NewSht ("func_data_list_4")
    Dim i As Integer, numrows As Integer
    'expects LBound to be 1
    numrows = UBound(pt4, 1)

    For i = 1 To numrows
        Cells(i, 1) = pt4(i, 1)
        Cells(i, 2) = pt4(i, 2)
        Cells(i, 3) = pt4(i, 3)
        Cells(i, 4) = pt4(i, 4)
    Next i
End Sub

Sub NewSht(strSheetName As String)
  Application.DisplayAlerts = False
  On Error Resume Next
  Worksheets.Add.Name = strSheetName
  Worksheets(strSheetName).Move after:=Worksheets(Worksheets.Count)
 End Sub

The new color object is actually very straightforward. It expands the number of colors available from 256 to over 16 million, and allows direct access to RGB values. It has connections to exterior color standards, such as Pantone and RAL numbers that can be very handy, but these are also just color matching RGB values.

The AcadAcCmColor Class creates an AcCmColor object. This color object is freestanding, it contains RED, GREEN, BLUE properties, and the method to set them. After there is a color in the container, the autocad entity you wish to color already has a TRUECOLOR property which is set equal to the color object. Once an entity has its color, the object used to color it is no longer necessary. The color object can have its RGB values changed and re-used. One color object can color everything in the drawing a different color.

Autodesk implemented the color object as an external program. It has to be loaded, its not very user friendly at first glance, but it can be used without fully knowing why its necessary, and once loaded it provides access to 16 million colors.

assuming two autocad objects have been created –

Dim color As AcadAcCmColor
Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.20")

Call color.SetRGB(80, 100, 244)
objent.TrueColor = color

Call color.SetRGB(244, 80, 100)
objent2.TrueColor = color

Color.SetRGB(R,G,B) is the main tool to be used, but there are others, especially with regard to the industry standard color books. You can use the ColorIndex property to set the ACI if you wish.

Autocad AcCmColor Object (ActiveX)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s