本帖最后由 198526 于 2012-4-27 20:53 编辑
- (defun c:aA (/ b chra color db dm dmm ent file_id file_idx h h1 i j la ll n name pt pt0 pt0x pt0y pt1 pt1x pt1y pt2 pt2x pt2y pt3
- ptslist r ss txt vtxlst x XDGC XDGC1 XDKD XDKD1)
- (defun dimtext (pt1 pt2)
- (setq pt1x (car pt1) pt1y (cadr pt1) pt2x (car pt2) pt2y (cadr pt2) pt0x (/ (+ pt1x pt2x) 2)
- pt0y (/ (+ pt1y pt2y) 2) pt0 (list pt0x pt0y) )
- (setq txt (rtos (distance pt1 pt2)) r (angle pt1 pt2) pt (polar pt0 (+ r (/ pi 2)) ll) b (assoc color a)
- db (list (caadr b) (cons (LIST txt (LIST PT0 PT1)) (cadadr b))) dm (strcat (car db) (itoa (length (cadr db)))))
- (IF
- (NOT(APPLY 'OR
- (mapcar '(lambda (N)
- (AND (EQUAL (READ TXT) (READ(CAR N)) XDGC)(NOT(inters pt0 pt1 (CAADR N) (CADADR N) NIL))(<= (distance pt0 (CAADR N)) XDKD))
- )
- (CADADR B); (CADADR B)遍历表内比较(TXT (PT1 PT2))是否一样
- )
- )
- )
- (PROGN
- (setq a (subst (list color db) b a ) )
- (maketext (strcat txt "(" dm ")") pt h r color la)
- )
- )
- )
- (defun maketext (txt pt h r color la)
- (entmake (list '(0 . "TEXT") (cons 8 la) (cons 62 color) (cons 10 pt) (cons 40 h) (cons 1 txt) (cons 50 r) '(41 . 0.8) '
- (72 . 1) (cons 11 pt) '(73 . 0) ) )
- )
- (setvar "cmdecho" 0)
- (vl-load-com)
- (if (setq h1 (getint "\n输入字高:<100>")) (setq h h1) (setq h 100) )
- (if (setq XDGC1 (getREAL "\n输入等长公差值:<1.>")) (setq XDGC XDGC1) (setq XDGC 1.) )
- (if (setq XDKD1 (getREAL "\n输入等长跨度值:<200.>")) (setq XDKD XDKD1) (setq XDKD 200.) )
-
-
- (setq ll (/ h 2) chra 65 a '())
- (setq ss (ssget '((0 . "LINE,LWPOLYLINE,POLYLINE"))))
- (repeat (setq i (sslength ss))
- (setq name (ssname ss (setq i (1- i))) ent (entget name) la (cdr (assoc 8 ent)))
-
- (if (not (assoc 62 ent))
- (setq color (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 ent)))))) ;获得随层的颜色
- (setq color (cdr (assoc 62 ent)))
- )
- (if (not (assoc color a)) (setq a (cons (list color (list (chr (+ chra (length a))) nil)) a)) )
- (if (= "LINE" (cdr (assoc 0 ent)))
- (progn(setq pt1 (cdr (assoc 10 ent)) pt2 (cdr (assoc 11 ent)))(dimtext pt1 pt2))
- (progn
- (if (= "LWPOLYLINE" (cdr (assoc 0 ent))) (setq n 2) (setq n 3))
- (setq vtxlst (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object name) 'coordinates))))
- (setq j 0 ptslist nil )
- (repeat (/ (length vtxlst) n)
- (setq ptslist (append ptslist
- (list (list (nth j vtxlst) (nth (1+ j) vtxlst) (if (= n 3) (nth (+ 2 j) vtxlst) 0.0 )) )
- ))
- (setq j (+ j n))
- )
- (setq pt1 nil pt2 nil)
- (foreach x ptslist ;遍历相邻两个点坐标
- (if (null pt1)(setq pt1 x pt3 x ) (setq pt2 x))
- (if pt2 (progn (dimtext pt1 pt2) (setq pt1 pt2)))
- )
- (if (= 1 (cdr (assoc 70 ent)))(dimtext pt2 pt3))
- )
- )
- )
- (setq file_idx (getfiled "指定输出文件路径" "" "xls" 1)
- file_id (open file_idx "w")
- )
- (write-line "颜色号码\t对应代码\t长度" file_id)
- (foreach b (reverse a)
- (setq dmm (strcat (itoa (car b)) "\t" (caadr b)) n 0 )
- (foreach x (reverse (cadadr b))
- (write-line (strcat dmm (itoa (setq n (1+ n))) "\t" (CAR x)) file_id)
- )
- )
- (close file_id)
- (princ)
- )
看看这个满意了没?
|