ปูนโยธา :
Act as a senior AutoCAD AutoLISP developer. Write one portable .lsp named PlotRectangles.lsp for AutoCAD Windows/Mac.
Goal: command PLOTRECTANGLES auto-plots every closed 4-vertex LWPOLYLINE rectangle on layer print to PDF pages.
Implement directly, no research needed. Use this schema:
- PR:collect-frames: ssget "_X" filter (0 . "LWPOLYLINE"), layer print, closed flag, vertex count = 4.
- PR:rect-window: get min/max XY from group code 10 vertices.
- PR:find-label: find TEXT,MTEXT,ATTRIB inside rectangle on layer name; use text as filename/page label.
- PR:safe-name: remove invalid filename chars :"/\|?*, trim spaces, max 80 chars.
- PR:sort-frames: sort top-to-bottom by Y, then left-to-right by X, with row tolerance.
- PR:ask-config: prompt user for output folder, PDF device, paper size, orientation, plot style; provide safe defaults, no hard-coded user paths.
- PR:plot-frame: call command-line _.-PLOT with Window plot area using rectangle p1/p2, fit to paper, center plot, plot styles optional.
- Main loop: for each sorted rectangle, plot to 0001_label.pdf, 0002_label.pdf, etc.
- Must restore sysvars using unwind-protect or error handler: CMDECHO, FILEDIA, BACKGROUNDPLOT.
- Must work with / and \ paths using helper PR:join-path.
- Do not depend on Python, AppleScript, external PDF tools, or fixed PC paths.
- If PDF merge is not safely available cross-platform, skip merge and output separate numbered PDFs.
- Add commands PLOTRECTANGLES and alias PR.
- Print clear progress and final output folder.
2026-07-05 13:25:39