Changing AutoCAD 2004 layer color

Discussion in 'AutoCAD' started by Mike Evans, Jan 13, 2004.

  1. Mike Evans

    Mike Evans Guest

    This is my first attempt at changing layer colors in AutoCAD 2004 (and
    dealing with the TrueColor property) using the object model.



    The examples I've found on the discussion boards involve calling the
    AcCmColor interface:



    (vla-getInterfaceObject (vlax-get-acad-object) "AutoCAD.AcCmColor.16")



    The way I did it, however, involved getting the TrueColor property of a
    layer, changing the color method and ACI color of the TrueColor AcCmColor
    object, then passing it back to the layer object.



    The sample code below uses this approach as it changes the color of layer
    "0" to blue (color 5).



    Is there a problem with this approach? Is a call to the AcCmColor interface
    required even when dealing with an existing object that already contains an
    AcCmColor object?



    Thank you for your help.





    (DEFUN c:bluelayer0 (/ layer_0_object truecolor colorindex)

    ;;

    ;; get layer 0 object

    (SETQ layer_0_object

    (VLA-ITEM

    (VLA-GET-LAYERS

    (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))

    ) ;_ VLA-GET-LAYERS

    "0"

    ) ;_ VLA-ITEM

    ) ;_ SETQ

    ;;

    ;; get TRUECOLOR property

    (SETQ truecolor

    (VLA-GET-TRUECOLOR

    layer_0_object

    ) ;_ VLA-GET-TRUECOLOR

    ) ;_ SETQ

    ;;

    ;; get COLORINDEX property

    (SETQ colorindex (VLA-GET-COLORINDEX truecolor))

    ;;

    ;; set COLORMETHOD to ACI

    (VLA-PUT-COLORMETHOD truecolor ACCOLORMETHODBYACI)

    ;;

    ;; set COLORINDEX to blue

    (VLA-PUT-COLORINDEX truecolor 5)

    ;;

    ;; set TRUECOLOR property of LAYER

    (VLA-PUT-TRUECOLOR layer_0_object truecolor)

    (PRINC)

    ) ;_ DEFUN
     
    Mike Evans, Jan 13, 2004
    #1
  2. Your approach is fine.

    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | This is my first attempt at changing layer colors in AutoCAD 2004 (and
    | dealing with the TrueColor property) using the object model.
    |
    |
    |
    | The examples I've found on the discussion boards involve calling the
    | AcCmColor interface:
    |
    |
    |
    | (vla-getInterfaceObject (vlax-get-acad-object) "AutoCAD.AcCmColor.16")
    |
    |
    |
    | The way I did it, however, involved getting the TrueColor property of a
    | layer, changing the color method and ACI color of the TrueColor AcCmColor
    | object, then passing it back to the layer object.
    |
    |
    |
    | The sample code below uses this approach as it changes the color of layer
    | "0" to blue (color 5).
    |
    |
    |
    | Is there a problem with this approach? Is a call to the AcCmColor
    interface
    | required even when dealing with an existing object that already contains
    an
    | AcCmColor object?
    |
    |
    |
    | Thank you for your help.
    |
    |
    |
    |
    |
    | (DEFUN c:bluelayer0 (/ layer_0_object truecolor colorindex)
    |
    | ;;
    |
    | ;; get layer 0 object
    |
    | (SETQ layer_0_object
    |
    | (VLA-ITEM
    |
    | (VLA-GET-LAYERS
    |
    | (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))
    |
    | ) ;_ VLA-GET-LAYERS
    |
    | "0"
    |
    | ) ;_ VLA-ITEM
    |
    | ) ;_ SETQ
    |
    | ;;
    |
    | ;; get TRUECOLOR property
    |
    | (SETQ truecolor
    |
    | (VLA-GET-TRUECOLOR
    |
    | layer_0_object
    |
    | ) ;_ VLA-GET-TRUECOLOR
    |
    | ) ;_ SETQ
    |
    | ;;
    |
    | ;; get COLORINDEX property
    |
    | (SETQ colorindex (VLA-GET-COLORINDEX truecolor))
    |
    | ;;
    |
    | ;; set COLORMETHOD to ACI
    |
    | (VLA-PUT-COLORMETHOD truecolor ACCOLORMETHODBYACI)
    |
    | ;;
    |
    | ;; set COLORINDEX to blue
    |
    | (VLA-PUT-COLORINDEX truecolor 5)
    |
    | ;;
    |
    | ;; set TRUECOLOR property of LAYER
    |
    | (VLA-PUT-TRUECOLOR layer_0_object truecolor)
    |
    | (PRINC)
    |
    | ) ;_ DEFUN
    |
    |
     
    R. Robert Bell, Jan 13, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.