AutoCAD Mechanical 2026
Use this skill when AutoCAD Mechanical 2026 is already running on Windows and the task is to attach to the open desktop app and draw a square in the current drawing.
Prefer COM automation over simulated typing inside AutoCAD. It is more reliable, easier to validate, and avoids focus problems.
Workflow
- Confirm that an AutoCAD Mechanical window is already open when the user says it is.
- Run scripts/draw-square-in-open-autocad.ps1 instead of rebuilding the COM logic by hand.
- Unless the user specifies otherwise, draw the square in model space with:
- side length
100 - origin
(0, 0)
- side length
- Regenerate the drawing and zoom extents after creation so the square is visible.
- Report the drawing name and the square parameters you used.
Quick Rules
- Assume Windows PowerShell and desktop AutoCAD Mechanical 2026.
- Attach to the active AutoCAD instance with COM using
Marshal.GetActiveObject. - Try
AutoCAD.Application.25.1first, then fall back to older generic AutoCAD ProgIDs if needed. - Draw the square as a closed lightweight polyline in model space.
- Do not depend on AutoCAD command-line text entry if the same result can be done through COM.
- If AutoCAD is not already open, stop and say that the application must be launched first.
- If there is no active drawing, create one only if the user explicitly asks; otherwise stop and explain the blocker.
Script Usage
Default square:
& ".\skills\autocad-mechanical-2026\scripts\draw-square-in-open-autocad.ps1"
Custom size and origin:
& ".\skills\autocad-mechanical-2026\scripts\draw-square-in-open-autocad.ps1" -Size 250 -OriginX 500 -OriginY 300
Output
The script prints a compact JSON object containing:
DocumentNameProgIdOriginSizeClosed
Use that output to confirm the operation succeeded.