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

  • Constructs a new AcCmColor.

    Parameters

    • Optionalmethod: AcCmColorMethod

      Initial color method (defaults to ByColor)

    • Optionalvalue: number

      Internal packed value

    Returns AcCmColor

Accessors

  • get blue(): undefined | number
  • Gets the blue component (0–255).

    Returns undefined | number

  • 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 colorMethod(): AcCmColorMethod
  • Gets the current color method.

    Returns AcCmColorMethod

  • set colorMethod(method: AcCmColorMethod): void
  • Sets the color method.

    Note: Changing the method does not modify _value.

    Parameters

    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 cssColor(): undefined | string
  • Gets the CSS RGB color string (e.g., "rgb(255,0,255)").

    Returns undefined | string

  • get green(): undefined | number
  • Gets the green component (0–255).

    Returns undefined | number

  • get hexColor(): undefined | string
  • Gets the hexadecimal representation of the color (e.g., "0xFF00FF").

    Returns undefined | string

  • get isByACI(): boolean
  • Returns true if the color method is ByACI.

    Returns boolean

  • get isByBlock(): boolean
  • Returns true if the color method is ByBlock.

    Returns boolean

  • get isByColor(): boolean
  • Returns true if the color method is ByColor (explicit RGB).

    Returns boolean

  • get isByLayer(): boolean
  • Returns true if the color method is ByLayer.

    Returns boolean

  • get red(): undefined | number
  • Gets the red component (0–255).

    Returns undefined | number

  • 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

  • Creates a clone of this color instance.

    Returns AcCmColor

    A new AcCmColor instance with the same method and value

  • Copies color values from another AcCmColor instance.

    Parameters

    Returns this

    The current instance

  • Checks equality with another color.

    Parameters

    Returns boolean

    True if color method and value are identical

  • Sets the color to ByBlock.

    Parameters

    • Optionalvalue: number

      Option layer color value

    Returns this

  • Sets the color to ByLayer.

    Parameters

    • Optionalvalue: number

      Option layer color value

    Returns this

  • Sets the RGB color.

    Parameters

    • r: number

      Red component (0–255)

    • g: number

      Green component (0–255)

    • b: number

      Blue component (0–255)

    Returns this

    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 this

    The current instance for chaining

  • Sets the RGB color by a single packed number (0xRRGGBB).

    Parameters

    • value: undefined | null | number

      Packed RGB number

    Returns this

  • Sets the color as a scalar grayscale value.

    Parameters

    • scalar: number

      Scalar value (0–255)

    Returns this

    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

  • Creates one AcCmColor from one string

    Parameters

    • name: string

    Returns undefined | AcCmColor