- Selects a line and determines its start, midpoint, and end.
- Calculates the angle of the line based on the start and end points.
- Inserts the block PIPE at the midpoint of the line with the correct rotation.
- Stretches the block so that its endpoints align with the start and end of the line.
This is what i m trying but somthing wrong here.
(defun c:linetopipe (/ ent start end mid ang insPt blkName blkScale)
(setq blkName "PIPE") ;; Block name
;; Select the line
(setq ent (car (entsel "\nSelect a line: ")))
(if (and ent (eq (cdr (assoc 0 (entget ent))) "LINE"))
(progn
;; Get start, midpoint, and end of the line
(setq start (cdr (assoc 10 (entget ent))))
(setq end (cdr (assoc 11 (entget ent))))
(setq mid (mapcar '(lambda (a b) (/ (+ a b) 2)) start end)) ;; Midpoint
;; Calculate angle of the line
(setq ang (angle start end))
;; Insert block at midpoint with calculated angle
(setq insPt mid)
(command "_.INSERT" blkName insPt "1" "1" ang)
;; Get last inserted block
(setq blk (entlast))
(if blk
(progn
;; Modify block's stretch points to fit the line
(command "_.STRETCH" "_C" blk "" start end)
)
)
)
(princ "\nSelected entity is not a line.")
)
(princ)
)