Changing an Objects Color

Use the Color property to read or set a drawing object's color. The Group and Layer objects also expose this property. Beginning with AutoCAD 2004, all objects have a new TrueColor property that supports the Color property. This new property uses RGB color values, Pantone color palettes, and color-book values. This property has the following syntax:

Object.Color = lngColor lngColor may be one of 257 colors, 9 of which are represented by the predefined AutoCAD AcColor constants detailed in Table 10-10.

Table 10-10. AcColor Constants

Constant

Color Index

Color

acByBlock

0

ByBlock

acRed

1

Red

acYellow

2

Yellow

acGreen

3

Green

acCyan

4

Cyan

acBlue

5

Blue

acMagenta

6

Magenta

acWhite

7

White or Black, depending on the screen background color

acByLayer

256

ByLayer

The following code changes the color of user-selected objects to green. Public Sub ColorGreen()

Dim objSelectionSet As AcadSelectionSet Dim objDrawingObject As AcadEntity

'choose a selection set name that you only use as temporary storage and 'ensure that it does not currently exist On Error Resume Next

ThisDrawing.SelectionSets("TempSSet").Delete

Set objSelectionSet = ThisDrawing.SelectionSets.Add("TempSSet")

'ask user to pick entities on the screen objSelectionSet.SelectOnScreen

For Each objDrawingObject In objSelectionSet objDrawingObject.Color = acGreen objDrawingObject.Update

Next objSelectionSet.Delete

End Sub

Was this article helpful?

+1 -2
100 Bowling Tips

100 Bowling Tips

Playing bowling with your friends can help you decide if it is indeed the hobby that you want to invest your time on today. Aside from that, it can help you get a better feel of the sport. More importantly, when you play with your friends, it would become a more fun activity, which you can look forward to each week.

Get My Free Ebook


Responses

  • marcus
    How to change object color in autocad?
    7 months ago

Post a comment