Rasterex API/docs/components/cad/api

API References

Technical reference for CAD layer and block snapshot/visibility messages.

Snapshot Requests

Use getBlocks for the list view. Use the returned block indexes to request details or attributes only when needed.

  • getLayers: Requests the current layer snapshot.
  • getBlocks: Requests the lightweight block list for table or sidebar UI.
  • getBlockDetails: Requests details and attributes for one block index or multiple indexes.
  • getBlockAttributes: Requests attributes only for one block index or multiple indexes.
type GetLayersMessage = {
  type: 'getLayers';
  payload?: { requestId?: string };
};

type GetBlocksMessage = {
  type: 'getBlocks';
  payload?: { requestId?: string };
};

type GetBlockAttributesMessage = {
  type: 'getBlockAttributes';
  payload: BlockDetailQueryPayload;
};

type GetBlockDetailsMessage = {
  type: 'getBlockDetails';
  payload: BlockDetailQueryPayload;
};

type BlockDetailQueryPayload = {
  requestId?: string;
  index?: number;
  indexes?: number[];
};
Snapshot Requests

Visibility Updates

Both visibility messages require a visible flag and support multiple target selectors so the host can address one or many items at once. After setLayerVisibility, the viewer sends layersSnapshot again with the current layer state.

  • setLayerVisibility: Targets layers by all, index, indexes, id, ids, name, or names.
  • setBlockVisibility: Targets blocks by all, index, indexes, name, or names.
type SetLayerVisibilityMessage = {
  type: 'setLayerVisibility';
  payload: {
    requestId?: string;
    visible: boolean;
    all?: boolean;
    index?: number;
    indexes?: number[];
    id?: string | number;
    ids?: Array<string | number>;
    name?: string;
    names?: string[];
  };
};

type SetBlockVisibilityMessage = {
  type: 'setBlockVisibility';
  payload: {
    requestId?: string;
    visible: boolean;
    all?: boolean;
    index?: number;
    indexes?: number[];
    name?: string;
    names?: string[];
  };
};
Visibility Updates

Canvas Responses

The canvas returns a lightweight block list separately from selected block detail and attribute payloads. Detail and attribute lookups always return a blocks array, even when no block matches.

type LayerSnapshotPayload = {
  requestId?: string;
  fileId?: string;
  fileIndex?: number;
  fileName?: string;
  layers: Array<{
    index?: number;
    id?: string | number;
    name?: string;
    color?: string;
    visible: boolean;
    kind: 'pdf' | 'vector';
    details?: {
      state?: number;
      defaultstate?: number;
      isplottable?: number;
      [key: string]: unknown;
    };
  }>;
};

type BlockSnapshotPayload = {
  requestId?: string;
  fileId?: string;
  fileIndex?: number;
  fileName?: string;
  blocks: Array<{
    index?: number;
    name?: string;
    visible: boolean;
    selected?: boolean;
    hasAttribute?: boolean;
  }>;
};

type BlockDetailSnapshotPayload = {
  requestId?: string;
  fileId?: string;
  fileIndex?: number;
  fileName?: string;
  blocks: Array<{
    index: number;
    name: string;
    details: {
      index: number;
      name: string;
      state: number;
      defaultstate: number;
      defaultcolor: string | null;
      color: string | null;
      fillstyle: string | null;
      defaultfillstyle: string | null;
      overridecolor: boolean;
      overridefill: boolean;
      hatchstyle: string | null;
      selected: boolean;
      listed: boolean;
      insert?: {
        blockhandleLow?: number;
        blockhandleHigh?: number;
        insertX?: number;
        insertY?: number;
        insertZ?: number;
        insertRot?: number;
        insertscaleX?: number;
        insertscaleY?: number;
        insertscaleZ?: number;
        blockref?: number;
        MinX?: number;
        MinY?: number;
        MaxX?: number;
        MaxY?: number;
        type?: string;
      };
      drawn: boolean;
      mouseon: boolean;
      hasAttribute: boolean;
      fold: number;
      bounds: {
        minX: number;
        minY: number;
        maxX: number;
        maxY: number;
        width: number;
        height: number;
        area: number;
      };
    };
    attributes: Array<{
      name: string;
      value: unknown;
      blockref?: number;
    }>;
  }>;
};
Canvas Responses

Block Detail Response Fields

blockDetailsSnapshot returns the selected block records plus request and file metadata. Every matching block includes details and attributes.

  • type: Message type returned by the canvas. For block details, this is blockDetailsSnapshot.
  • payload.requestId: Optional request correlation value echoed from getBlockDetails.
  • payload.fileId, payload.fileIndex, payload.fileName: Active file metadata for the snapshot.
  • payload.blocks: Matching block records. The array is empty when no requested index matches.
  • block.index, block.name: Block index and name at the wrapper level for quick list/detail matching.
  • details.index, details.name: Block index and name repeated inside the raw detail object.
  • details.state, details.defaultstate: Current and default CAD block state values.
  • details.defaultcolor, details.color: Default and current colors. Values are hex strings when supplied by the canvas.
  • details.fillstyle, details.defaultfillstyle, details.hatchstyle: Fill and hatch style values, or null when unavailable.
  • details.overridecolor, details.overridefill: Flags indicating whether current style values override defaults.
  • details.selected, details.listed, details.drawn, details.mouseon: Viewer flags for current UI/list/draw/hover state.
  • details.hasAttribute: True when the block has attribute data.
  • details.fold: Fold/group value returned by the viewer.
  • details.insert.blockhandleLow, blockhandleHigh: CAD handle values for the inserted block reference.
  • details.insert.insertX, insertY, insertZ: Insert position values in drawing coordinates.
  • details.insert.insertRot: Insert rotation value.
  • details.insert.insertscaleX, insertscaleY, insertscaleZ: Insert scale values for each axis.
  • details.insert.blockref: Referenced block index/id for the insert.
  • details.insert.MinX, MinY, MaxX, MaxY: Raw insert extents returned by the canvas.
  • details.insert.type: Numeric representation used for insert values, such as float.
  • details.bounds.minX, minY, maxX, maxY: Computed block bounds in canvas coordinates.
  • details.bounds.width, height, area: Computed block dimensions and area.
  • attributes[].name, attributes[].value, attributes[].blockref: Attribute tag name, value, and owning block reference.

Block Detail Events

Use these events when wiring a block list to a details panel.

window.addEventListener('message', (event) => {
  const { type, payload } = event.data || {};

  if (type === 'blocksSnapshot') {
    console.log(payload.blocks);
  }

  if (type === 'blockDetailsSnapshot') {
    const block = payload.blocks[0];
    console.log(block.details?.insert);
    console.log(block.details?.bounds?.width);
    console.log(block.details?.bounds?.height);
    console.log(block.details?.bounds?.area);
    console.log(block.attributes);
  }

  if (type === 'blockAttributesSnapshot') {
    console.log(payload.blocks[0]?.attributes);
  }
});
Block Detail Events