- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
Using AutoCAD 2025LT.
I am seeking a LISP routine for 'copy-array-fit' sequence that allows you to -
- select object to copy
- select copy basepoint
- select copy point 1
- select copy point 2
- designate maximum spacing between objects copied between point 1 and point 2.
I am struggling to write or find a LISP that works consistently.
Below is the closest I have come to a consistently working 'copy-array-fit' with MAX spacing routine:
(defun C:copy-array-fit-max-spacing ()
(setq PT1 nil PT2 nil OSN (getvar "osmode") LFAC (getvar "dimlfac"))
(princ "\nSelect objects to array: ")
(setq ENTOBJS (ssget))
(if ENTOBJS
(progn
(setq ENTOBJ (ssname ENTOBJS 0))
(if ENTOBJ (setq ENT (entget ENTOBJ)))
(setq PT1 (cdr (assoc 10 ENT)))
(setvar "osmode" 0)
;; Get second point
(while (not PT2)
(setq PT2 (getpoint PT1 "\nPick array end point: "))
)
;; Compute distance, angle, and spacing
(setq PTANG (angle PT1 PT2))
(setq SPACE (/ (getdist "\nEnter spacing: ") LFAC))
(setq PT-DIST (distance PT1 PT2))
(setq NUMTO (fix (/ PT-DIST SPACE)))
;; Ensure at least one object is copied
(if (= NUMTO 0)
(princ "\nSpacing too large for array.")
(progn
;; Compute exact spacing to ensure alignment
(setq SPACE (/ PT-DIST NUMTO))
;; Loop through and copy objects with exact placement
(setq i 1)
(while (<= i NUMTO)
(setq NEWPT (list (+ (car PT1) (* i SPACE (cos PTANG)))
(+ (cadr PT1) (* i SPACE (sin PTANG)))))
(command "copy" ENTOBJS "" PT1 NEWPT)
(setq i (1+ i))
)
)
)
(setvar "osmode" OSN)
(princ (strcat "\n" (itoa NUMTO) " objects arrayed with exact spacing: " (rtos SPACE 2 4)))
)
)
(princ)
)
Issues:
- Works sporadically
- At times places objects spaced correctly, though places the 2nd object over the 1st object.
- At times places objects spaced correctly, though places the 2nd object over the 1st object and 2nd last object over the last object.
- Routine copies objects one less time that it should.
Any help would be much appreciated.
Solved! Go to Solution.