你先试试,总觉得有些问题,可却无法改正
调试图,注意块的名字
- (defun Getinterpoints (ent1 ent2 / e1 e2 pt1 pt2 pt3 pt4)
- (setq e1 (entget ent1))
- (setq e2 (entget ent2))
- (setq pt1 (cdr (assoc 10 e1)))
- (setq pt2 (cdr (assoc 11 e1)))
- (setq pt3 (cdr (assoc 10 e2)))
- (setq pt4 (cdr (assoc 11 e2)))
- (inters pt1 pt2 pt3 pt4)
- )
- (defun GetAllInters (ss / n i j ent1 ent2 points point)
- (setq n (sslength ss))
- (setq i 0
- j 0
- )
- (while (< i n)
- (setq j (1+ i))
- (setq ent1 (ssname ss i))
- (while (< j n)
- (setq ent2 (ssname ss j))
- (if (setq point (getinterpoints ent1 ent2))
- (setq points (append points (list point)))
- )
- (setq j (1+ j))
- )
- (setq i (1+ i))
- )
- points
- )
- (defun c:test (/ ss n i pts pt pt_next dist BlkName)
- (setq os (getvar "osmode"))
- (setq cmd (getvar "cmdecho"))
- (setq ss (ssget '((0 . "LINE"))))
- (command "_.undo" "be")
- (setvar "osmode" 0)
- ;(setvar "cmdecho" 0)
- (setq pts (GetAllInters ss))
- (setq pts (vl-sort pts '(lambda (e1 e2) (< (car e1) (car e2)))))
- (setq pts (vl-sort pts '(lambda (e1 e2) (< (cadr e1) (cadr e2)))))
- (setq n (length pts))
- (setq i 0)
- (while (< i (1- n))
- (setq pt (nth i pts))
- (setq pt_next (nth (1+ i) pts))
- (if (equal (cadr pt) (cadr pt_next))
- (progn
- (setq dist (distance pt pt_next))
- (cond
- ((equal dist 5 0.00000001) (setq BlkName "Len5"))
- ((equal dist 11 0.00000001) (setq BlkName "Len11"))
- )
- (command "_.insert"
- BlkName
- (list (/ (+ (car pt) (car pt_next)) 2)
- (/ (+ (cadr pt) (cadr pt_next)) 2)
- )
- ""
- ""
- ""
- )
- )
- )
- (setq i (1+ i))
- )
- (setq pts (vl-sort pts '(lambda (e1 e2) (< (car e1) (car e2)))))
- (setq i 0)
- (while (< i (1- n))
- (setq pt (nth i pts))
- (setq pt_next (nth (1+ i) pts))
- (if (equal (car pt) (car pt_next))
- (progn
- (setq dist (distance pt pt_next))
- (cond
- ((equal dist 5) (setq BlkName "Len5"))
- ((equal dist 11) (setq BlkName "Len11"))
- )
- (command "_.insert"
- BlkName
- (list (/ (+ (car pt) (car pt_next)) 2)
- (/ (+ (cadr pt) (cadr pt_next)) 2)
- )
- ""
- ""
- "90"
- )
- )
- )
- (setq i (1+ i))
- )
- (command "_.undo" "e")
- (setvar "osmode" os)
- (setvar "cmdecho" cmd)
- (princ)
- )
|