本帖最后由 198526 于 2012-4-26 13:31 编辑
 - (defun c:aa (/ color ent h i ll la layer layers name pt pt0 pt0x pt0y pt1 pt1x pt1y pt2 pt2x pt2y r ss txt DM DB file_idX file_id dmm)
- (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)
- )
- )
- )
- (setq h 100) ; 字体高度
- (setq ll 50) ; 距离直线
- (SETQ CHRA 65)
- (SETQ A '())
- (setq ss (ssget '((0 . "LINE,POLYLINE"))));暂不支持PL线
- (repeat (setq i (sslength ss))
- (setq name (ssname ss (setq i (1- i))))
- (setq ent (entget name))
- (setq color (vla-get-color (vlax-ename->vla-object name)))
- (setq la (cdr (assoc 8 ent)))
- (IF (NOT(ASSOC COLOR A))
- (sETQ A (CONS (LIST COLOR (LIST (CHR (+ CHRA (LENGTH A))) NIL)) A ) )
- )
- (SETQ B (ASSOC COLOR A))
- (IF (= "LINE" (cdr (assoc 0 ent)))
- (PROGN
- (setq pt1 (cdr (assoc 10 ent)))
- (setq pt2 (cdr (assoc 11 ent)))
- (setq pt1x (car pt1))
- (setq pt1y (cadr pt1))
- (setq pt2x (car pt2))
- (setq pt2y (cadr pt2))
- (setq pt0x (/ (+ pt1x pt2x) 2))
- (setq pt0y (/ (+ pt1y pt2y) 2))
- (setq pt0 (list pt0x pt0y))
- (setq txt (rtos (distance pt1 pt2)))
- (setq r (angle pt1 pt2))
- (setq pt (polar pt0 (+ r (/ pi 2)) ll))
- (SETQ DB (LIST (CAADR B) (CONS TXT (CADADR B))))
- (SETQ DM (STRCAT (CAR DB) (ITOA (LENGTH (CADR DB)))))
- (sETQ A (SUBST
- (LIST COLOR DB)
- B
- A
- )
- )
- (maketext (STRCAT txt "(" DM ")") pt h r color la)
- )
- )
-
- )
- (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" x) file_id) )
- )
- ;根据langjs 大师的程序加了一些,更接近楼主想要了,不过PL线的还没写,楼主可以尝试自己写一下。
- (close file_id)
-
- (princ)
- )
|