Class representing transparency similar to AutoCAD’s AcCmTransparency.

Stores both method and alpha information.

Constructors

  • Creates a new transparency object.

    Parameters

    • Optionalalpha: number

      When provided, constructs with ByAlpha method and sets alpha. Must be between 0 and 255.

    Returns AcCmTransparency

Accessors

  • get alpha(): number
  • Gets the alpha value. Only meaningful if method === ByAlpha.

    Returns number

  • set alpha(alpha: number): void
  • Sets the alpha value and force the method to ByAlpha.

    Parameters

    • alpha: number

      0–255 alpha, clamped internally if out of range

    Returns void

  • get isByAlpha(): boolean
  • True if the method is ByAlpha.

    Returns boolean

  • get isByBlock(): boolean
  • True if the method is ByBlock.

    Returns boolean

  • get isByLayer(): boolean
  • True if the method is ByLayer.

    Returns boolean

  • get isClear(): boolean
  • True if transparency is exactly clear (alpha==0 and ByAlpha).

    Returns boolean

  • get isInvalid(): boolean
  • True if current state is invalid (ErrorValue).

    Returns boolean

  • get isSolid(): boolean
  • True if transparency is solid (alpha==255 and ByAlpha).

    Returns boolean

  • get percentage(): undefined | number
  • Gets the AutoCAD-style transparency percentage.

    Mapping rules:

    • 0% = fully opaque (alpha = 255)
    • 100% = fully transparent (alpha = 0)

    This matches how AutoCAD displays and stores transparency values in UI and DXF files.

    If the transparency method is not ByAlpha, this method returns undefined, because AutoCAD does not define a percentage for ByLayer or ByBlock.

    Returns undefined | number

    Transparency percentage (0–100), or undefined

  • set percentage(percentage: number): void
  • Sets the transparency using an AutoCAD-style percentage.

    Mapping rules (AutoCAD compatible):

    • 0% → fully opaque (alpha = 255)
    • 100% → fully transparent (alpha = 0)

    Internally, the alpha value is calculated as: alpha = round(255 × (1 − percentage / 100))

    This method:

    • Forces the transparency method to ByAlpha
    • Clamps the percentage to the range 0–100
    • Preserves ObjectARX value semantics

    Parameters

    • percentage: number

      Transparency percentage (0–100)

    Returns void

    This instance (for fluent chaining)

    const t = new AcCmTransparency();
    t.setPercentage(50); // ≈ alpha 128

    t.setPercentage(0); // alpha = 255 (opaque)
    t.setPercentage(100); // alpha = 0 (clear)

Methods

  • Creates a deep copy of this transparency object.

    This mirrors the value-semantics of ObjectARX AcCmTransparency, where copying results in an independent object with the same transparency method and alpha value.

    Returns AcCmTransparency

    A new AcCmTransparency instance with identical state.

  • Compares this transparency with another one for equality.

    Two AcCmTransparency objects are considered equal if:

    • Their transparency methods are identical
    • Their alpha values are identical

    This mirrors the value semantics of ObjectARX AcCmTransparency.

    Parameters

    Returns boolean

    True if both represent the same transparency

    const a = new AcCmTransparency(128);
    const b = new AcCmTransparency(128);
    a.equals(b); // true
  • Convert this transparency to an integer suitable for storage. Uses a simple bit-encoding: high­bits for method and low­bits for alpha.

    31 24 23 8 7 0 +-------------+--------------+------------+ | flags | reserved | alpha | +-------------+--------------+------------+

    Returns number

  • Returns a human-readable string representation of the transparency.

    Behavior:

    • "ByLayer" if transparency is inherited from layer
    • "ByBlock" if transparency is inherited from block
    • Numeric alpha value ("0""255") if method is ByAlpha

    This format is intentionally simple and mirrors common AutoCAD UI and DXF text usage.

    Returns string

    String representation of the transparency

    new AcCmTransparency().toString();        // "ByLayer"
    new AcCmTransparency(128).toString(); // "128"
  • Deserialize an integer back into a transparency object.

    Parameters

    • value: number

      32-bit stored transparency representation

    Returns AcCmTransparency

  • Creates an AcCmTransparency instance from a string representation.

    Accepted formats:

    • "ByLayer" (case-insensitive)
    • "ByBlock" (case-insensitive)
    • Numeric alpha value "0""255"

    Invalid or out-of-range values will produce an ErrorValue transparency.

    Parameters

    • value: string

      String to parse

    Returns AcCmTransparency

    Parsed AcCmTransparency instance

    AcCmTransparency.fromString("ByLayer");
    AcCmTransparency.fromString("128");
    AcCmTransparency.fromString("ByBlock");