Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to know if it will work on AutoCAD LT for my project. I have the full version but it needs to work on AutoCAD LT 2024 as well and I don't have a way to test it.
(defun c:PlacePiers (/ pt1 pt2 numBlocks blkName dist angle spacing pt offset i dx dy threshold overlap)
(setq blkName "PIER") ; Default block name
; Prompt user to select two points
(setq pt1 (getpoint "\nSelect the first point: "))
(setq pt2 (getpoint "\nSelect the second point: "))
; Calculate the distance between the two points
(setq dist (distance pt1 pt2))
; Calculate the change in x and y
(setq dx (- (car pt2) (car pt1)))
(setq dy (- (cadr pt2) (cadr pt1)))
; Calculate the angle using atan
(setq angle (atan dy dx))
; Prompt user for the number of blocks
(setq numBlocks (getint "\nEnter the number of blocks to place: "))
(if (not numBlocks) (setq numBlocks 1)) ; Default to 1 if no input
; Calculate the spacing between blocks
(setq spacing (/ dist (1- numBlocks)))
; Set a threshold for overlap checking
(setq threshold 0.01) ; Adjust this value as needed
; Loop to place blocks along the line
(setq i 0)
(repeat numBlocks
(setq offset (* spacing i))
(setq pt (polar pt1 angle offset))
; Check if the point is too close to existing "PIER" blocks
(setq overlap nil)
(setq ent (entnext)) ; Start with the first entity in the drawing
(while ent
(setq entData (entget ent))
; Check if the entity is a "PIER" block
(if (and (= (cdr (assoc 0 entData)) "INSERT")
(equal (cdr (assoc 2 entData)) blkName)) ; Check if the block name is "PIER"
(if (< (distance pt (cdr (assoc 10 entData))) threshold)
(setq overlap t)
)
)
(setq ent (entnext ent)) ; Move to the next entity
)
; Only place block if no overlap
(if (not overlap)
(progn
; Create block reference at specified point
(entmake (list (cons 0 "INSERT")
(cons 2 blkName)
(cons 10 pt)
(cons 41 1) ; X scale
(cons 42 1) ; Y scale
(cons 50 0) ; Rotation angle
))
)
)
(setq i (1+ i))
)
(princ "\nBlocks placed successfully.")
(princ)
)
Solved! Go to Solution.