flytoday
发表于 2012-7-4 07:59:21
kexiya123
发表于 2012-7-4 09:05:16
看看列子,为修改成其他程序有帮助
hao3ren
发表于 2012-7-4 09:37:39
其实我自己也不会写程序,只不过以前有时间翻了下书,如果只是小修改自己可以尝试下
用(princ (entget (car (entsel))))这句可以获得图元组码
hao3ren
发表于 2012-7-4 09:38:29
;;; 框选封闭区域面积到excel by:langjs
;;; ==================
(defun c:qq (/ d ent f i lst m2 obj pt ss txt x y)
(setq TextHeight (getdist "\n输入标注文字高度:"))
(defun maketext (txt pt) ; 生成文字子函数
(entmake (list '(0 . "TEXT") (cons 62 1) (cons 10 pt) (cons 40 TextHeight) (cons 1 txt) '(41 . 0.8)))
)
(setvar "cmdecho" 0)
(vl-load-com)
(setq ss (ssget) ent (entlast))
(command ".region" ss "")
(setq ss (ssadd)lst nil)
(while (setq ent (entnext ent))
(if (= (cdr (assoc 0 (entget ent))) "REGION")
(setq obj (vlax-ename->vla-object ent) pt (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj)))
m2 (rtos (vla-get-area obj) 2 2) d (rtos (vla-get-perimeter obj) 2 2) lst (cons (list pt m2 d) lst)
)
)
)
(command ".undo" "")
(setq lst (vl-sort lst (function (lambda (x y)(< (car (car x)) (car (car y)))))))
(setq lst (vl-sort lst (function (lambda (x y)(> (cadr (car x)) (cadr (car y)))))))
(setq f (getfiled "指定输出文件路径" "" "xls" 1) f (open f "w"))
(write-line "编号\t周长(mm)\t面积(mm2)" f)
(setq i 1)
(foreach x lst
(setq pt (car x) m2 (cadr x) d (caddr x))
(maketext (strcat "A" (itoa i)) (list (car pt) (+ (cadr pt) (* 1.2 TextHeight))))
(maketext (strcat "L=" d "mm") pt)
(maketext (strcat "S=" m2 "mm2") (list (car pt) (- (cadr pt) (* 1.2 TextHeight))))
(write-line (strcat (strcat "A" (itoa i)) "\t" d "\t" m2) f)
(setq i (1+ i))
)
(close f)
(princ)
)
flytoday
发表于 2012-7-4 17:59:46
还缺一个编号前缀能更改……………
hao3ren
发表于 2012-7-4 18:10:06
(defun c:qq (/ d ent f i lst m2 obj pt ss txt x y)
(setq TextHeight (getdist "\n输入标注文字高度:")
Textbh (getstring "\n输入编号前缀:"))
(defun maketext (txt pt) ; 生成文字子函数
(entmake (list '(0 . "TEXT") (cons 62 1) (cons 10 pt) (cons 40 TextHeight) (cons 1 txt) '(41 . 0.8)))
)
(setvar "cmdecho" 0)
(vl-load-com)
(setq ss (ssget) ent (entlast))
(command ".region" ss "")
(setq ss (ssadd)lst nil)
(while (setq ent (entnext ent))
(if (= (cdr (assoc 0 (entget ent))) "REGION")
(setq obj (vlax-ename->vla-object ent) pt (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj)))
m2 (rtos (vla-get-area obj) 2 2) d (rtos (vla-get-perimeter obj) 2 2) lst (cons (list pt m2 d) lst)
)
)
)
(command ".undo" "")
(setq lst (vl-sort lst (function (lambda (x y)(< (car (car x)) (car (car y)))))))
(setq lst (vl-sort lst (function (lambda (x y)(> (cadr (car x)) (cadr (car y)))))))
(setq f (getfiled "指定输出文件路径" "" "xls" 1) f (open f "w"))
(write-line "编号\t周长(mm)\t面积(mm2)" f)
(setq i 1)
(foreach x lst
(setq pt (car x) m2 (cadr x) d (caddr x))
(maketext (strcat Textbh (itoa i)) (list (car pt) (+ (cadr pt) (* 1.2 TextHeight))))
(maketext (strcat "L=" d "mm") pt)
(maketext (strcat "S=" m2 "mm2") (list (car pt) (- (cadr pt) (* 1.2 TextHeight))))
(write-line (strcat (strcat "A" (itoa i)) "\t" d "\t" m2) f)
(setq i (1+ i))
)
(close f)
(princ)
)
呵呵,为什么不自己试着修改下呢
xiaodao520
发表于 2012-7-4 18:21:45
hao3ren 发表于 2012-7-4 18:10 static/image/common/back.gif
(defun c:qq (/ d ent f i lst m2 obj pt ss txt x y)
(setq TextHeight (getdist "\n输入标注文字高度:") ...
输出的excel编号与图形中标注的标注前缀名不一致,大师再改改,满足flytoday
hao3ren
发表于 2012-7-4 19:04:38
本帖最后由 hao3ren 于 2012-7-4 19:05 编辑
(defun c:qq (/ d ent f i lst m2 obj pt ss txt x y)
(setq TextHeight (getdist "\n输入标注文字高度:")
Textbh (getstring "\n输入编号前缀:"))
(defun maketext (txt pt) ; 生成文字子函数
(entmake (list '(0 . "TEXT") (cons 62 1) (cons 10 pt) (cons 40 TextHeight) (cons 1 txt) '(41 . 0.8)))
)
(setvar "cmdecho" 0)
(vl-load-com)
(setq ss (ssget) ent (entlast))
(command ".region" ss "")
(setq ss (ssadd)lst nil)
(while (setq ent (entnext ent))
(if (= (cdr (assoc 0 (entget ent))) "REGION")
(setq obj (vlax-ename->vla-object ent) pt (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj)))
m2 (rtos (vla-get-area obj) 2 2) d (rtos (vla-get-perimeter obj) 2 2) lst (cons (list pt m2 d) lst)
)
)
)
(command ".undo" "")
(setq lst (vl-sort lst (function (lambda (x y)(< (car (car x)) (car (car y)))))))
(setq lst (vl-sort lst (function (lambda (x y)(> (cadr (car x)) (cadr (car y)))))))
(setq f (getfiled "指定输出文件路径" "" "xls" 1) f (open f "w"))
(write-line "编号\t周长(mm)\t面积(mm2)" f)
(setq i 1)
(foreach x lst
(setq pt (car x) m2 (cadr x) d (caddr x))
(maketext (strcat Textbh (itoa i)) (list (car pt) (+ (cadr pt) (* 1.2 TextHeight))))
(maketext (strcat "L=" d "mm") pt)
(maketext (strcat "S=" m2 "mm2") (list (car pt) (- (cadr pt) (* 1.2 TextHeight))))
(write-line (strcat (strcat Textbh (itoa i)) "\t" d "\t" m2) f)
(setq i (1+ i))
)
(close f)
(princ)
)
我真的要崩溃了
461045462
发表于 2012-7-4 20:54:23
谢谢 langjs hao3ren
辛苦了!
flytoday
发表于 2012-7-4 22:41:50
本帖最后由 flytoday 于 2012-7-4 23:00 编辑
还可更完美………就是能进行二次输出exl就是说能增加个命令当进行编号编辑改动……通过一个命令二次输出………