Creates a new 2D CAD viewer instance.
Configuration options for the viewer
Options to customize view
Optionalbackground?: numberBackground color
OptionalcalculateSizeCallback?: AcEdCalculateSizeCallbackCallback function used to calculate size of canvas when window resized
Optionalcontainer?: HTMLElementContainer HTML element used by renderer
Protected_The HTML canvas element for rendering
Protected_The HTML element to contain this view
ReadonlyeventsEvents fired by the view for various interactions
Fired when mouse hovers over an entity
Fired when mouse moves over the view
Fired when a frame is rendered
Fired when mouse stops hovering over an entity
Fired when the view camera is changed
Fired when the view is resized
The block table record id associated with the active layout
The active layout view
Gets the background color of the view.
The color is represented as a 24-bit hexadecimal RGB number, e.g.,
0x000000 for black.
Sets the background color of the view.
The background color as a 24-bit hexadecimal RGB number
The bounding box to include all entities in this viewer
CAD scene graph used for rendering and HTML export.
The canvas HTML element used by this view
Sets global celtscale
Gets the center point of the current view in world coordinates.
The view center point
Gets the center point of the current view in world coordinates.
The view center point
The HTML element to contain this view
Current mouse position in canvas-local screen coordinates (pixels).
Note: this is NOT viewport/client coordinates; use canvasToViewport()
when browser-viewport coordinates are required by DOM APIs.
Postion of current mouse in world coordinate system
Gets the input manager for handling user interactions.
The editor provides high-level methods for getting user input like point selection, entity selection, and cursor management.
The editor instance
Height of canvas (not height of window) in pixel
The HTML transient elements manager for placing overlays anchored to world coordinates.
The internal THREE camera used by current active layout.
The internal THREE scene used by this view.
Gets whether the view needs to be re-rendered.
True if the view is dirty and needs re-rendering
Sets whether the view needs to be re-rendered.
True to mark the view as needing re-rendering
True while addEntity batch-conversion callbacks are still running.
Parsing can report 100% before this reaches zero; callers opening files should wait on this (as zoomToFitDrawing does) before hiding progress UI or assuming the canvas is ready.
Sets global ltscale
Gets information about missing data during rendering (fonts and images).
Object containing maps of missing fonts and images
Gets the current view mode.
The view mode determines how the view responds to user interactions:
The current view mode
Sets the view mode (selection or pan).
The view mode to set
The block table record id of the model space
Whether entity conversion during document open is deferred for progressive display.
Gets the Three.js renderer wrapper used for CAD rendering.
The renderer instance
Gets the size of the selection box used for entity picking.
This determines how close the mouse needs to be to an entity to select it, measured in screen pixels.
Selection box size in pixels
Sets the size of the selection box used for entity picking.
Selection box size in pixels
The selection set in current view.
The statistics of the current scene
Width of canvas (not width of window) in pixel
Add the specified entity or entities in drawing database into the current scene and draw it or them
Input one or multiple entities to add into the current scene
Add the specified layer in drawing database into the current scene
Input the layer to add into the current scene
Add the specified layout in drawing database into the current scene
Input the layout to add into the current scene
Add the specified transient entity or entities into this view
Input one or multiple transient entities
Enables progressive camera framing while entities are batch-converted at document open. Pair with zoomToFitDrawing for the final accurate fit.
Converts canvas-local coordinates into container-local coordinates.
This is useful for DOM overlays mounted in container while CAD APIs
return screen points in canvas space.
Converts canvas-local coordinates into viewport/client-space coordinates.
Clear the scene
ProtectedclearClears the current hover state and cancels all hover-related timers.
ProtectedcollectCollects ids using window or crossing selection rules.
ProtectedcreateDisables progressive open framing after the final zoom-to-fit runs.
Converts every drawable entity into the scene before offline export.
Interactive viewing skips off/frozen layers for performance; HTML snapshots store layer visibility separately and need full geometry so the exported layer panel can toggle layers on later.
Converted geometry remains in the live scene after this call completes.
Optionaloptions: { includeInvisibleLayers?: boolean }Moves the current view to the specified 2D point at the given scale.
Target location in world coordinates to fly the view to.
The optional target zoom scale to apply after the transition. If not specified, the scale will not change.
Returns the current scene visibility for one entity.
Returns the selection action based on modifier keys. Shift: remove, Ctrl/Cmd: add, default: replace.
Returns selection mode based on drag direction in canvas coordinates. Left-to-right = window selection, right-to-left = crossing selection.
Returns preview styles for selection rectangle.
Returns true when the entity is already present in the scene.
Select the specified entities
ProtectedinitializeProtectedInitializes the viewer after renderer and camera are created.
This method sets up the initial cursor and can be overridden by child classes to add custom initialization logic.
Marks a layout as already framed by an external caller (typically
AcApDocManager.onAfterOpenDocument, which zooms the startup
layout right after parsing). Subsequent first-visit async zoom
callbacks (applyInitialZoom, zoomToFitDrawing(..., layoutBtrId))
for this btrId are suppressed so they do not override the
application layer's initial camera.
This is the public counterpart of the _initializedLayouts set —
exposed so the application layer can stay in sync with the view's
notion of "which layouts have been framed already" without
needing access to private state.
Called when hovering the specified entity
Called when unhovering the specified entity
ProtectedonOptionalpoint: AcGeVector2dLikeOptionalhitRadius: numberOptionalpickOneOnly: booleanpaper space layouts the selection pipeline supports
"drill-through": clicks inside a viewport rectangle resolve against
the model-space entities that are visually rendered through that
viewport, rather than picking the viewport's border. Clicks near
the border still pick the AcDbViewport entity itself so the user
can grip, move, lock or delete the viewport.
This mirrors AutoCAD web behaviour (single-click selection of
model content through the viewport). The desktop ARX behaviour
(explicit MSPACE/PSPACE modes, CVPORT system variable, double-click
to enter mspace) is a separate, larger feature — tracked in
.claude/plans/next_14_viewports_full.md PR-γ Option A. We
intentionally do not implement it here.
The border vs interior decision uses a tolerance derived from
selectionBoxSize (the same pixel-sized hit radius used elsewhere
in pick) converted to paper-space WCS via pointToBox. This keeps
the gesture consistent with how other entity edges behave — you
don't have to land pixel-perfect on the viewport line to grab it.
Remove the specified entity or entities from current drawing database and current scene and draw it or them
Input one or multiple entities to remove
Remove the specified transient entity from this view
Input the object id of the transient entity to remove
Re-render points with latest point style settings
Input display mode of points
Converts a point from screen coordinates to world coordinates.
The screen coordinate system has its origin at the top-left corner of the canvas, with Y increasing downward. World coordinates use the CAD coordinate system with Y typically increasing upward.
Point in screen coordinates
Point in world coordinates
Search entities intersected or contained in the specified bounding box.
Input the query bounding box
Return query results
Select entities intersected with the specified point in the world coordinate system, add them to the current selection set, and highlight them.
Optionalpoint: AcGeVector2dLikeSelect entities intersected with the specified bounding box in the world coordinate system, add them to the current selection set, and highlight them.
Input one bounding box in the world coordinate system.
Select entities by box with window/crossing behavior.
Set callback function used to calculate size of canvas when window resized
Input callback function
Updates scene visibility for one entity without changing the database.
Re-reads layout background sysvars from the active database. Called after a document is opened so DWG-stored values take effect.
Unhighlight the specified entities
Update the specified entity or entities
Input the entity or entities to update
Updates entity visibility without rebuilding batched geometry.
Update the specified layer in the current scene
The layer to update
Changes made to the layer
Converts a viewport/client-space point (e.g. MouseEvent.clientX/Y) into canvas-local coordinates.
Converts a viewport/client-space point into container-local coordinates.
Temporarily switches the view mode, executes an action, then restores the previous mode — even if the action throws.
This is the mode-level counterpart of AcEditor.withCursor and follows the same save → set → restore pattern.
The temporary view mode to apply
The async (or sync) action to run under the temporary mode
The value returned by the action
Converts a point from world coordinates to screen coordinates.
This is the inverse of screenToWorld(), converting from the CAD world
coordinate system to screen pixel coordinates.
Point in world coordinates
Point in screen coordinates
Zooms the view to fit the specified bounding box with optional margin.
This method adjusts the view's center and zoom level so that the entire specified bounding box is visible within the viewport. The margin parameter adds extra space around the bounding box to provide visual padding.
The bounding box to zoom to, in world coordinates
Additional margin around the bounding box (in world units)
Zooms the view to fit all visible entities in the current drawing.
This method automatically calculates the bounding box of all entities currently displayed in the view and adjusts the view's center and zoom level to show the entire scene. This is useful for getting an overview of the entire drawing or after loading new content.
This function takes effect only if the current view has finished rendering all entities. When opening a file, progressive Rendering is used to render entities incrementally. So this function will wait until all of entities rendered or a timeout occurs.
Maximum time (ms) to wait before executing zoom to fit action. Default: 0 (no timeout).
OptionallayoutBtrId: stringZooms the view to fit all visible entities in the current scene.
This method automatically calculates the bounding box of all entities currently displayed in the specified layer and adjusts the view's center and zoom level to show the entire layer. This is useful for getting an overview of the entire layer of one drawing or after loading new content.
The layer name
A 2D CAD viewer component that renders CAD drawings using Three.js.
This class extends AcEdBaseView and provides functionality for:
Example