Represents an AutoCAD color. This class supports color methods:

  • ByColor: explicit RGB
  • ByACI: AutoCAD Color Index (0-256)
  • ByLayer: color inherited from layer
  • ByBlock: color inherited from block

Constructors

Accessors

  • get colorIndex(): undefined | number
  • Gets the AutoCAD Color Index (ACI), or undefined if not ByACI, ByBlock, or ByLayer.

    Returns undefined | number

  • set colorIndex(index: undefined | number): void
  • Sets the AutoCAD Color Index (0–256).

    • 0 sets the color method to ByBlock
    • 256 sets the color method to ByLayer
    • 1–255 sets the color method to ByACI

    Parameters

    • index: undefined | number

      ACI index

    Returns void

  • get colorName(): undefined | string
  • Gets the color name.

    For ByColor or ByACI, resolves the name via AcCmColorUtil. For ByLayer or ByBlock, returns the corresponding string.

    Returns undefined | string

  • set colorName(name: undefined | string): void
  • Sets the color by name.

    Resolves the name to an RGB value via AcCmColorUtil.

    Parameters

    • name: undefined | string

      Color name

    Returns void

  • get RGB(): undefined | number
  • Gets the packed RGB value (0xRRGGBB).

    • For ByColor, returns _value directly
    • For ByACI, converts index to RGB via AcCmColorUtil
    • For ByLayer or ByBlock, returns _value directly

    Returns undefined | number

Methods

  • Sets the RGB color.

    Parameters

    • r: number

      Red component (0–255)

    • g: number

      Green component (0–255)

    • b: number

      Blue component (0–255)

    Returns AcCmColor

    The current instance for chaining

  • Sets the RGB color from a CSS color string.

    Examples:

    • "#FF00FF"
    • "#F0F"
    • "rgb(255,0,255)"
    • "rgba(255,0,255,0.5)"
    • "red" (named colors)

    Parameters

    • cssString: string

      CSS color string

    Returns AcCmColor

    The current instance for chaining

  • Returns a string representation of the color.

    • "ByLayer" for ByLayer colors
    • "ByBlock" for ByBlock colors
    • One number for color index
    • Three comma-separated numbers for RGB color

    Returns string