Class representing transparency similar to AutoCAD’s AcCmTransparency.

Stores both method and alpha information.

Constructors

Accessors

  • 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

  • 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"
  • 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");