Get Viewport Selection
selection_getRetrieve entities pre-selected in the AutoCAD viewport (pickfirst) to scope operations to exactly those objects. Returns handles and entity details for downstream automation.
Instructions
Read the entities the user pre-selected in the AutoCAD viewport (COM backend only).
Returns the implied "pickfirst" selection — the entities highlighted with grips before invoking the AI — so work can be scoped to exactly those entities instead of the whole drawing. Typical use::
sel = selection_get()
dimension_auto(sel["handles"], style="chain")Result keys: ok — True on the COM backend (even for an empty selection) count — number of selected entities handles — list of entity handles (hex strings) to act on entities — full per-entity info (type, layer, color, ...) pickfirst — state of the PICKFIRST sysvar (None if unknown) message — guidance when nothing is selected
On the ezdxf headless backend there is no viewport, so this returns ok=False with an empty handles list.
fields / compact shape the "entities" collection — this tool already
returns an object, so the columnar envelope lands under that key rather
than replacing the result. handles is unaffected, so a caller that only
wants handles can pass fields=["handle"] and still read handles directly.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | Project to these fields, in this order (e.g. ['handle','type','layer']); 'properties.<key>' reaches one nested value. Omit for the full record; an unknown name errors and lists the valid ones. | |
| compact | No | Return a columnar {fields, rows, count, offset, total, truncated, next_offset} envelope instead of dicts: much cheaper per row, and the only shape that reports truncation. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||