各位大神,不知道能不能帮忙改下代码?
这个插件是统计工作量的,GYTS-6B1、GYTS-12B1是材料型号,上面的管58、架24、余10;是该材料数量在哪里用掉的量,我现在有个插件可以批量统计出各材料型号及量,但插件只支持上面数值的表示格式是:管XX+架XX+余XX这种格式的,但是我们一般用到的格式是管XX 架XX 余XX---------------------以下是插件代码---------------------------------------------------
(defun c:zz()
(if *error* quit)
(setq cmdmode (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq myosmode (getvar "osmode"))
(setvar "osmode" 0)
(prompt "\n选择计算工作量对象: ")
(setq sset (ssget))
(if (null sset)
(princ "\n错误: 没有选择对象!\n")
;过滤出选中的“text”实体nsset。
(progn
(setq ssl (sslength sset))
(setq nsset (ssadd)) ;“text”实体
(setq nsset1 (ssadd)) ;工作量实体
(setq nsset2 (ssadd)) ;光、电缆程式实体
(while (> ssl 0)
(setq temp (ssname sset (setq ssl(1- ssl))))
(if (= (cdr (assoc 0 (entget temp))) "TEXT")
(ssadd temp nsset)
)
)
(setq ssl (sslength nsset))
;选出形如"墙20+架10"的对象和"HYA10*0.4"。
(setq total 0)
(setq ssl1 ssl)
(setq ssl2 ssl)
(while (> ssl1 0)
(setq temp (ssname nsset (setq ssl1 (1- ssl1))))
(setq txt0 (cdr (assoc 1 (entget temp))))
(selecttxt_dlcs)
(selecttxt_gzl)
)))
(gzl_duihao)
(gzl_guilei)
(gzl_culture)
(gzl_viewresult)
(setvar "OSMODE" myosmode)
(setvar "CMDECHO" cmdmode)
(prin1)
)
;;;选出形如"墙20+架10"
(defun selecttxt_gzl()
(setq re_call 0)
(setq txt_l (strlen txt0))
;形如"墙2*******"
(if (> txt_l 2)
(if (and (> (ascii (substr txt0 1 1)) 128) (> (ascii (substr txt0 2 1)) 128) (< (ascii (substr txt0 3 1)) 58) (> (ascii (substr txt0 3 1)) 47))
(progn
(setq txt0 (substr txt0 3 (- txt_l 2)))
(setq re_call 1)
)))
;形如"20.5+******"
;形如"20.5"
(if (and (< (ascii (substr txt0 1 1)) 58) (> (ascii (substr txt0 1 1)) 47) (= re_call 0))
(progn
(setq i 0)
(while (< i txt_l)
(setq i (1+ i))
(setq txt_it (ascii (substr txt0 i 1)))
(if (and (= txt_it 43) (< i txt_l))
(progn
(setq txt0 (substr txt0 (+ i 1) (- txt_l i)))
(setq i txt_l)
(setq re_call 1)))
(if (and (or (> txt_it 57) (< txt_it 43) (= txt_it 44) (= txt_it 45) (= txt_it 47)) (= re_call 0))
(progn
(setq i txt_l)
(setq re_call 2)))
(if (and (= i txt_l) (= re_call 0))
(if (and (< txt_it 58) (> txt_it 47))
(ssadd temp nsset1))
)
)
)
)
(if (= re_call 1) (selecttxt_gzl))
)
;;;选出"HYA"、"GYT"、"GYS"文字数
(defun selecttxt_dlcs()
(setq txt_l (strlen txt0))
(if (> txt_l 3)
(if (or (= (substr txt0 1 3) "HYA") (= (substr txt0 1 3) "GYT") (= (substr txt0 1 3) "GYS"))
(ssadd temp nsset2))
)
)
;;;工作量与电缆程式对号
(defun gzl_duihao()
(setq duihao_ls1 nil)
(setq duihao_ls2 nil)
(setq nsset1_len (sslength nsset1))
(while (> nsset1_len 0)
(setq duihao_yes 0)
(setq nsset1_temp (ssname nsset1 (setq nsset1_len (1- nsset1_len))))
(setq nsset1_rd (cdr (assoc 50 (entget nsset1_temp))))
(setq nsset1_pt (cdr (assoc 10 (entget nsset1_temp))))
(setq nsset1_pt (list (car nsset1_pt) (cadr nsset1_pt)))
(setq nsset2_len (sslength nsset2))
(while (> nsset2_len 0)
(setq nsset2_temp (ssname nsset2 (setq nsset2_len (1- nsset2_len))))
(setq nsset2_rd (cdr (assoc 50 (entget nsset2_temp))))
(if (or (< (abs (- nsset1_rd nsset2_rd)) 0.1) (> (abs (- nsset1_rd nsset2_rd)) 6.2))
(progn
(setq nsset2_pt (cdr (assoc 10 (entget nsset2_temp))))
(setq nsset2_pt (list (car nsset2_pt) (cadr nsset2_pt)))
(setq dis_n1n2 (distance nsset1_pt nsset2_pt))
(if (< dis_n1n2 12) ;指定插入点间距范围
(progn
(setq n1n2_rd (- (angle nsset2_pt nsset1_pt) nsset1_rd))
(setq dis_yn1n2 (abs (* dis_n1n2 (sin n1n2_rd))))
(if (and (< dis_yn1n2 5) (>= n1n2_rd 0) (<= n1n2_rd Pi))
(progn
(setq duihao_yes 1)
(setq nsset2_temp1 nsset2_temp))
(if (and (< dis_yn1n2 5) (= duihao_yes 0))
(progn
(setq duihao_yes 1)
(setq nsset2_temp1 nsset2_temp))
))
))
)
)
)
(if (= duihao_yes 0)
(progn
(setq duihao_lstemp nil)
(setq duihao_lstemp (cdr (assoc 1 (entget nsset1_temp))))
(setq duihao_ls2 (cons duihao_lstemp duihao_ls2))
))
(if (= duihao_yes 1)
(progn
(setq duihao_lstemp nil)
(setq duihao_lstemp (cons (cdr (assoc 1 (entget nsset2_temp1))) (cdr (assoc 1 (entget nsset1_temp)))))
(setq duihao_ls1 (cons duihao_lstemp duihao_ls1))
(ssdel nsset2_temp1 nsset2)
))
)
)
;归类
(defun gzl_guilei(/ guilei_temp1 guilei_temp2 guilei_temp3 guilei_temp4)
(setq guilei_temp1 duihao_ls1)
(setq guilei_result nil)
(while (/= guilei_temp1 nil)
(setq guilei_temp2 (car guilei_temp1))
(setq guilei_temp3 (car guilei_temp2))
(setq guilei_temp1 (cdr guilei_temp1))
(if (/= guilei_result nil)
(progn
(if (/= (assoc guilei_temp3 guilei_result) nil)
(progn
(setq guilei_temp4 (cdr guilei_temp2))
(setq guilei_temp4 (strcat (cdr (assoc guilei_temp3 guilei_result)) "+" guilei_temp4))
(setq guilei_result (subst (cons guilei_temp3 guilei_temp4) (assoc guilei_temp3 guilei_result) guilei_result))
)
(setq guilei_result (cons guilei_temp2 guilei_result)))
)
(setq guilei_result (cons guilei_temp2 guilei_result)))
)
)
;计算工作量文字
(defun gzl_culture(/ cu_temp1 cu_temp2 cu_temp3 cu_temp4 cu_temp5 cu_temp6 cu_temp7 cu_temp8)
(setq cu_result nil)
(setq cu_temp1 guilei_result)
(while (/= cu_temp1 nil)
(setq cu_temp6 nil)
(setq cu_temp2 (car cu_temp1))
(setq cu_temp3 (cdr cu_temp2))
(setq cu_temp1 (cdr cu_temp1))
(while (> (setq cu_te3_len (strlen cu_temp3)) 0)
(setq i 0)
(while (< i cu_te3_len)
(setq i (1+ i))
(setq cu_temp4 (substr cu_temp3 i 1))
(if (= cu_temp4 "+")
(progn
(setq cu_temp5 (substr cu_temp3 1 (- i 1)))
(setq cu_temp3 (substr cu_temp3 (+ i 1)))
(setq i cu_te3_len)
)
(if (= i cu_te3_len)
(progn
(setq cu_temp5 cu_temp3)
(setq cu_temp3 ""))))
)
(if (and (< (ascii (substr cu_temp5 1 1)) 58) (> (ascii (substr cu_temp5 1 1)) 47))
(setq cu_temp7 (cons " " cu_temp5))
(setq cu_temp7 (cons (substr cu_temp5 1 2) (substr cu_temp5 3))))
(if (or (= cu_temp6 nil) (= (assoc (car cu_temp7) cu_temp6) nil))
(setq cu_temp6 (cons cu_temp7 cu_temp6))
(progn
(setq cu_temp8 (rtos (+ (atof (cdr (assoc (car cu_temp7) cu_temp6))) (atof (cdr cu_temp7)))))
(setq cu_temp6 (subst (cons (car cu_temp7) cu_temp8) (assoc (car cu_temp7) cu_temp6) cu_temp6))
))
)
(setq cu_result (cons (cons (car cu_temp2) cu_temp6) cu_result))
)
)
;显示结果
(defun gzl_viewresult(/ viere_temp1 viere_temp2)
(setq viere_temp1 cu_result)
(while (/= viere_temp1 nil)
(setq viere_temp2 (car viere_temp1))
(setq viere_temp1 (cdr viere_temp1))
(princ viere_temp2)
(princ "\n")
)
(if (= duihao_ls2 nil)
(princ "无可疑数据,图纸很标准。")
(progn
(princ "以下数据为可疑数据,请认真核对:\n")
(princ duihao_ls2)
))
)
这个插件是统计工作量的,GYTS-6B1、GYTS-12B1是材料型号,上面的管58、架24、余10;是该材料数量在哪里用掉的量,我现在有个插件可以批量统计出各材料型号及量,但插件只支持上面数值的表示格式是:管XX+架XX+余XX这种格式的,但是我们一般用到的格式是管XX 架XX 余XX 插件是以前在论坛里找的,现在找不到那个帖子了。按照插件的要求是:管XX+架XX 这个是在一个单行文字里输入的,但我平时用的是管XX 架XX ,每一个都是一个单行文字 代码太长了,而且又没测试图
你试下把这句(setq guilei_temp4 (strcat (cdr (assoc guilei_temp3 guilei_result)) "+" guilei_temp4))
改成(setq guilei_temp4 (strcat (cdr (assoc guilei_temp3 guilei_result)) guilei_temp4))
试试看 jian445906829 发表于 2018-5-3 18:14
插件是以前在论坛里找的,现在找不到那个帖子了。按照插件的要求是:管XX+架XX 这个是在一个单行文字里输入 ...
既然自己不会,就尽可能按现成的要求做。原来要求在一个单行文字内,你分成两个,如何确定哪个对应哪个?程序就完全不一样了。 对啊,这得要改很多代码的吧 看到Lisp就头痛,为什么不用VC开发
页:
[1]