- UID
- 153703
- 积分
- 75
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-6-29
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这是个材料表生成程序,就是从输入的文本里提取出数据,然后导入CAD,生成相应的材料表。大家帮忙看看这段程序有什么问题,在CAD2006里运行正常,而在CAD2007里运行就不正常了,表现在:
选择文件后读取里面的量,再赋给变量,却发现是空的,举其中的一个例子,变量"mc"。是不是(defun edit_i ()程序有问题啊,大家帮忙看一下,给一点意见!!
(defun C:DDCLB (/ dcl_id a str ilist item m10 m11 ny nl ny1 clbbt clbth pcl1 pcl2 nj l1
ivar zflen do_open checkda edit_i clb inse dclb ddclb_main)
;判断字符串长度函数,将全角字符视为一个字符.
(defun zflen (s / s1 s2)
(setq s1 s)
(setq MSL (strlen s1))
(while (> (strlen s1) 0)
(cond
((= (ascii s1) 37) ;是否"%"
(setq s2 (substr s1 2))
(if (= (ascii s2) 37) (setq s1 (substr s1 3) MSL (- MSL 2)) (setq s1 s2)));cond1
((> (ascii s1) 126) ;是否全角字符
(setq s1 (substr s1 3) MSL (1- MSL)));cond2
(T (setq s1 (substr s1 2))));cond
);while
(ai_return MSL)
);defun
;-------------------
;Function to open MAT data file.
(defun do_open (/ file f item)
(setq file (getfiled "打开安装材料表数据文件 *.CLB" "" "clb" 2))
(setq zl1 1 zl2 0)
(if (/= file nil)
(progn
(setq f (open file "r") item (read-line f) ilist '())
(setq ilist (cons item ilist))
(while (/= (setq item (read-line f)) nil)
(if (= (ascii item) 64) (setq zl2 (+ zl2 1)))
(setq zl1 (+ zl1 1))
(setq ilist (cons item ilist)))
(close f)
(setq ilist (reverse ilist))
(set_tile "txtfile" file)
));if
(setq zl (/ (float (+ zl1 zl2)) 28)) ;总数
(if (> zl (float (fix zl))) (setq zl (+ 1 zl)))
(setq zl (fix zl))
(if (= (length ilist) 0) (set_tile "txtfile" "按左边的按钮选择数据文件."))
)
;Function to check the data file
(defun checkda()
(if (/= ilist nil) (done_dialog 1)
(alert "您必须选择一个安装材料表数据文件,才能生成表格!")
))
;-------------------
(defun edit_i ()
(setq a 1)
(while (and (/= "\t" (substr item a 1)) (/= "" (substr item a 1))) (setq a (1+ a)))
(setq str (substr item 1 (1- a)) item (substr item (1+ a)))
)
;-------------
;Funtion to draw the MAT table.
(defun clb (/ pt pc pc1 pc2 pc3 pm pxh pth pmc pgg psl pcl pdz pzz pbz
pth1 pth2 pbz1 pa nl len len1 i l b n n1 str item th xh
mc gg sl cl dz zz bz pcp b_n b_n1 hei islong m_color)
(initget 1)
(setq pt (getpoint "\n 请输入材料表的左下角点:"))
(command "osnap" "off")
(command "color" "bylayer")
(setq m_color (cdr (assoc '62 (tblsearch "LAYER" (getvar "clayer")))))
(if (= m_color 1) (setq m_color 4) (setq m_color 1))
(prompt "\n 正在生成材料表,请稍等!")
(command "insert" "C:/tecad/drawsize/clbt" pt k "" 0)
(setq pc (polar pt (/ pi 2) (* 10 k))
pc1 (polar pc 0 (* 180 k))
pc2 (polar pc (/ pi 2) k)
pm (polar pc (/ pi 2) (* 3.5 k))
pxh (polar pm 0 (* 4 k))
pth (polar pxh 0 (* 18 k))
pmc (polar pc2 0 (* 37 k))
pgg (polar pmc 0 (* 28.5 k))
psl (polar pm 0 (* 97 k))
pcl (polar psl 0 (* 17 k))
pdz (polar pcl 0 (* 18.5 k))
pzz (polar pdz 0 (* 15 k))
pbz (polar pc2 0 (* 157.5 k))
b_n nil b_n1 nil islong nil
)
(setq pth1 (polar pc2 0 (* 8.5 k))
pth2 (polar pc2 0 (* 35.5 k))
pa (/ pi 2) nl 0 len (length ilist) len1 (1+ len) i 0
)
(command "pline" pc "w" (* 0.5 k) (* 0.5 k) pc1 "")
(command "line" pc pc1 "")
(command "array" "l" "" "R" len1 1 (* 8 k))
(setq pc3 (polar pc pa (* len 8 K)))
(command "pline" pc pc3 "")
(setq l (ssget "l"))
(setq b '(8 28 55 12 22 15 15 25) n1 0)
(foreach n b
(setq n1 (+ n1 n))
(setq pcp (polar pc 0 (* n1 k)))
(command "copy" l "" pc pcp)
)
(foreach item ilist
(edit_i)
(if (= "*" str) (setq th "") (setq th str))
(if (/= "@" th) (progn
(edit_i)
(if (= "*" str) (setq mc "") (setq mc str))
(edit_i)
(if (= "*" str) (setq gg "") (setq gg str))
(cond ((= gg "L5") (setq b_n "c5" b_n1 T))
((= gg "L6.3") (setq b_n "c63" b_n1 T))
((= gg "L8") (setq b_n "c8" b_n1 T))
((= gg "L10") (setq b_n "c10" b_n1 T))
((= gg "L12.6") (setq b_n "c126" b_n1 T))
((= gg "L12") (setq b_n "c12" b_n1 T))
((or (= gg "L14") (= gg "L14a")) (setq b_n "c14a" b_n1 T))
((= gg "L14b") (setq b_n "c14b" b_n1 T))
((= gg "L16a") (setq b_n "c16a" b_n1 T))
((= gg "L16") (setq b_n "c16" b_n1 T))
((= gg "L18a") (setq b_n "c18a" b_n1 T))
((= gg "L18") (setq b_n "c18" b_n1 T))
((= gg "L20a") (setq b_n "c20a" b_n1 T))
((= gg "L20") (setq b_n "c20" b_n1 T))
((= gg "L22a") (setq b_n "c22a" b_n1 T))
((= gg "L22") (setq b_n "c22" b_n1 T))
((= gg "L25a") (setq b_n "c25a" b_n1 T))
((= gg "L25b") (setq b_n "c25b" b_n1 T))
((= gg "L25c") (setq b_n "c25c" b_n1 T))
((= gg "L28a") (setq b_n "c28a" b_n1 T))
((= gg "L28b") (setq b_n "c28b" b_n1 T))
((= gg "L28c") (setq b_n "c28c" b_n1 T))
((= gg "L32a") (setq b_n "c32a" b_n1 T))
((= gg "L32b") (setq b_n "c32b" b_n1 T))
((= gg "L32c") (setq b_n "c32c" b_n1 T))
((or (= gg "%%c1.25\"") (= gg "%%C1.25\"")) (setq b_n "m_125" b_n1 T))
((or (= gg "%%c1.5\"") (= gg "%%C1.5\"")) (setq b_n "m_15" b_n1 T))
((or (= gg "%%c2.5\"") (= gg "%%C2.5\"")) (setq b_n "m_25" b_n1 T))
(T (setq b_n1 nil)));cond
(edit_i)
(if (= "*" str) (setq sl "") (setq sl str))
(edit_i)
(if (= "*" str) (setq cl "") (setq cl str))
(edit_i)
(if (= "*" str) (setq dz "") (setq dz str))
(edit_i)
(if (= "*" str) (setq zz "") (setq zz str))
(if (= "*" item) (setq bz "") (setq bz item))
(setq i (1+ i) xh (itoa i) nj (* 8 k nl))
(command "text" "s" "standard" "m" (polar pxh pa nj) (* 3 k) 0 xh)
(if (> (ascii th) 126) (setq hei (* 4.5 k)) (setq hei (* 3 k)));if
(if (> (strlen th) 12)
(command "text" "f" (polar pth1 pa nj) (polar pth2 pa nj) hei th)
(command "text" "m" (polar pth pa nj) hei 0 th)
)
(if (> (strlen mc) 14)
(if (> (zflen mc) 7) (progn (setq islong T) (COMMAND "color" m_color))));if
(command "text" "s" "hz" (polar pmc pa nj) (* 4 k) 0 mc)
(command "color" "bylayer")
(if (not b_n1) (progn
(if (> (strlen gg) 11)
(if (> (zflen gg) 11) (progn (setq islong T) (COMMAND "color" m_color))));if
(command "text" (polar pgg pa nj) (* 3 k) 0 gg) (command "color" "bylayer")
) (command "insert" (strcat "C:/tecad/wgd/" b_n) (polar pgg pa nj) k "" 0));if
(command "text" "m" (polar psl pa nj) (* 3 k) 0 sl)
(if (> (ascii cl) 126) (command "text" "m" (polar pcl pa nj) (* K 5) 0 cl)
(command "text" "m" (polar pcl pa nj) (* k 3) 0 cl))
(command "text" "m" (polar pdz pa nj) (* 3 k) 0 dz)
(command "text" "m" (polar pzz pa nj) (* 3 k) 0 zz)
(if (> (ascii bz) 126) (command "text" (polar pbz pa nj) (* 4.5 k) 0 bz)
(command "text" (polar pbz pa nj) (* 3.0 k) 0 bz))
(setq nl (1+ nl))
);progn
(progn (edit_i) (if (= "*" str) (setq mc "") (setq mc str))
(setq i 0 nj (* 8 k nl))
(command "text" (polar pmc pa nj) (* 5 k) 0 mc)
(setq nl (1+ nl))
));if
);foreach
(if (= 1 m_color) (setq m_color "红色") (setq m_color "青色"))
(if islong (alert (strcat "部分内容因字符较多可能出现交错现象!\n请检查表格中的" m_color "文字。\n\n提示:可使用文本修改命令进行修改!")))
;;LCA - WARNING: The OSMODE sysvar has changed.
(prompt "\n 材料表生成完毕! OK!") (setvar "osmode" ivar)
(princ)
)
;---------------------------------------------------------
;以下程序为生成单张材料表.
;Funtion to insert the table
(defun inse ()
(setq nl 0)
(grtext -1 (strcat "正在生成材料表" "第" (itoa ny) "页!"))
(command "insert" "C:/tecad/drawsize/m_dclb.dwg" pt 1 "" 0)
(setq pxh (mapcar '+ pt (list 29 264)) pmc1 (mapcar '+ pt (list 33.5 262))
pmc2 (mapcar '+ pt (list 66.5 262)) pgg1 (mapcar '+ pt (list 67.5 262))
pgg2 (mapcar '+ pt (list 100.5 262)) pbz1 (mapcar '+ pt (list 178 262))
pbz2 (mapcar '+ pt (list 204 262)) pcl (mapcar '+ pt (list 111 263))
pclh (mapcar '+ pt (list 111 264))
psl (mapcar '+ pt (list 139.5 263.5)) pdz (mapcar '+ pt (list 153.5 263.5))
pdz1 (mapcar '+ pt (list 147.5 262)) pdz2 (mapcar '+ pt (list 158.5 262))
pzz (mapcar '+ pt (list 168.5 263.5)) pbt (mapcar '+ pt (list 103 21))
pzz1 (mapcar '+ pt (list 162.5 261)) pzz2 (mapcar '+ pt (list 174.5 261))
pth (mapcar '+ pt (list 174 17)) pz1 (mapcar '+ pt (list 143 9))
pz2 (mapcar '+ pt (list 189 9)) pcl1 (mapcar '+ pt (list 104 262))
pcl2 (mapcar '+ pt (list 119 262)) pgg (mapcar '+ pt (list 68 262))
pdw (mapcar '+ pt (list 126.5 264.5)) pgc1 (mapcar '+ pt (list 118.5 37.5))
pgc (mapcar '+ pt (list 141.5 39.5)) pgc2 (mapcar '+ pt (list 164.5 37.5))
ptzm (mapcar '+ pt (list 160 24.5)) pz (mapcar '+ pt (list 170 9))
);setq
(command "text" "s" "standard" "m" pgc 4 0 clbgc) ;打印工程名
(command "text" "s" "standard" "M" ptzm 6 0 clbbt) ;打印图纸名
;;; (command "text" "s" "standard" "M" ptzm 6 0 zl2) ;打印图纸名
(setq clbth1 clbth)
(if (/= zl 1) (setq clbth (strcat clbth "(" (itoa ny) "/" (itoa zl) ")")))
(command "text" "m" pz 3.5 0 clbth) ;打印号
(setq clbth clbth1)
(setq p_ny1b (cons pz2 p_ny1b))
(command "textstyle" "standard")
(if m_@ (progn (command "text" "s" "st" pmc1 4 0 mc) (setq m_@ nil nl 1)));if
)
;Funtion to draw the dclb table.
(defun dclb (/ pt pmc1 pmc2 pgg1 pgg2 pbt pxh pth pz1 pz2 psl pcl pdz pzz pbz1 pdw
pbz2 pa nl len len1 i l b n n1 str item th xh ny ny1 he pgg pdz1 pdz2
mc gg sl cl dz zz bz b_n b_n1 pzz1 pzz2 m_@ p_ny1b ilong il)
(if (= m10 0) (progn (initget 1)
(setq pt (getpoint "\n 请选择材料表左下角的插入点:")))
(setq pt (list 0 0 0))
)
(if (> zl 12) (alert "对不起,先生(小姐)!由于你的材料表的页数超过了12页,超出了此程序的范围!请关闭程序,谢谢你的使用!"))
(setq ptr (mapcar '+ pt (list 892 -10)))
(setq ptl (mapcar '+ pt (list -10 951)))
(setq ptsc pt)
(command "osnap" "off")
(prompt "\n 正在生成材料表,请稍等!")
(setvar "users3" (strcat "(" (strcat "\"" clbgc "\"") (strcat "\"" clbbt "\"") (strcat "\"" clbth "\")")))
(setq pt1 pt)
(setq ny 1 pa (* pi 1.50) l1 0 m_@ nil p_ny1b nil ilong 0 il (length ilist))
(command "zoom" "l" pt 800)
(setq i 0 b_n nil b_n1 nil)
(inse)
(foreach item ilist
(setq ilong (1+ ilong))
(edit_i)
(if (= "*" str) (setq th "") (setq th str))
(edit_i)
(if (= "*" str) (setq mc "") (setq mc str))
(if (/= th "@") (progn
(edit_i)
(if (= "*" str) (setq gg "") (setq gg str))
(cond ((= gg "L6.3") (setq b_n "c63" b_n1 T))
((= gg "L8") (setq b_n "c8" b_n1 T))
((= gg "L10") (setq b_n "c10" b_n1 T))
((= gg "L12.6") (setq b_n "c126" b_n1 T))
((= gg "L12") (setq b_n "c12" b_n1 T))
((or (= gg "L14") (= gg "L14a")) (setq b_n "c14a" b_n1 T))
((= gg "L14b") (setq b_n "c14b" b_n1 T))
((= gg "L16a") (setq b_n "c16a" b_n1 T))
((= gg "L16") (setq b_n "c16" b_n1 T))
((= gg "L18a") (setq b_n "c18a" b_n1 T))
((= gg "L18") (setq b_n "c18" b_n1 T))
((= gg "L20a") (setq b_n "c20a" b_n1 T))
((= gg "L20") (setq b_n "c20" b_n1 T))
((= gg "L22a") (setq b_n "c22a" b_n1 T))
((= gg "L22") (setq b_n "c22" b_n1 T))
((= gg "L25a") (setq b_n "c25a" b_n1 T))
((= gg "L25b") (setq b_n "c25b" b_n1 T))
((= gg "L25c") (setq b_n "c25c" b_n1 T))
((= gg "L28a") (setq b_n "c28a" b_n1 T))
((= gg "L28b") (setq b_n "c28b" b_n1 T))
((= gg "L28c") (setq b_n "c28c" b_n1 T))
((= gg "L32a") (setq b_n "c32a" b_n1 T))
((= gg "L32b") (setq b_n "c32b" b_n1 T))
((= gg "L32c") (setq b_n "c32c" b_n1 T))
((or (= gg "%%c1.25\"") (= gg "%%C1.25\"")) (setq b_n "m_125" b_n1 T))
((or (= gg "%%c1.5\"") (= gg "%%C1.5\"")) (setq b_n "m_15" b_n1 T))
((or (= gg "%%c2.5\"") (= gg "%%C2.5\"")) (setq b_n "m_25" b_n1 T))
(T (setq b_n1 nil)));cond
(edit_i)
(if (= "*" str) (setq sl "") (setq sl str))
(edit_i)
(if (= "*" str) (setq cl "") (setq cl str))
(edit_i)
(if (= "*" str) (setq dz "") (setq dz str))
(edit_i)
(if (= "*" str) (setq zz "") (setq zz str))
(if (= "*" item) (setq bz "") (setq bz item))
(setq i (1+ i) xh (itoa i) nj (* 8 nl))
(command "text" "s" "n" "m" (polar pxh pa nj) 3 0 xh)
;;; (if (/= mc "钢 板" or "钢板") (command "text" "m" (polar psl pa nj) 2.8 0 sl))
(if (= mc "钢 板" or "钢板") (setq dw "")
(setq dw "个"))
;;; (if (= (substr mc (1- (strlen mc)) 2) "管") (setq dw "米"))
;;; (if (= (substr mc (1- (strlen mc)) 2) "钢") (setq dw "米"))
(if (= mc "钢 板" or "钢板") (setq dw "" sl "" dz ""))
(princ "123456")
(setq mc "eeeee")
(command "text" "s" "standard" "m" (polar pdw pa nj) 5 0 dw)
(if (<= (strlen mc) 16)
(command "text" "s" "hz" (polar pmc1 pa nj) 4 0 mc)
(command "text" "s" "hz" "f" (polar pmc1 pa nj) (polar pmc2 pa nj) 4 mc))
(if (= th "@") (setq th "" dw "") )
;(command "text" "s" "standard" "m" (polar pdw pa nj) 5 0 dw)
(if (> (strlen th) 11)
(command "text" "s" "hz" "f" (polar pbz1 pa nj) (polar pbz2 pa nj) 4 th)
(command "text" "s" "hz" (polar pbz1 pa nj) 3 0 th))
(if (not b_n1)
(if (>= (zflen gg) 15)
(command "text" "f" (polar pgg1 pa nj) (polar pgg2 pa nj) 3 gg)
(command "text" (polar pgg pa nj) 3 0 gg))
(command "insert" (strcat "C:/tecad/wgd/" b_n) (polar pgg pa nj) 1 "" 0));if
(if (> (ascii cl) 126) (setq he 4) (setq he 3)) ;写材栏
(cond ((and (= he 4) (> (strlen cl) 8)) (command "text" "f" (polar pcl1 pa nj) (polar pcl2 pa nj) he cl))
((= he 4) (command "text" "m" (polar pclh pa nj) he 0 cl))
((and (= he 3) (> (strlen cl) 7)) (command "text" "f" (polar pcl1 pa nj) (polar pcl2 pa nj) he cl))
((= he 3) (command "text" "m" (polar pcl pa nj) he 0 cl))
)
(command "text" "m" (polar psl pa nj) 3 0 sl)
(if (> (strlen dz) 5)
(command "text" "f" (polar pdz1 pa nj) (polar pdz2 pa nj) 3 dz)
(command "text" "m" (polar pdz pa nj) 3 0 dz))
(if (> (strlen zz) 6)
(command "text" "f" (polar pzz1 pa nj) (polar pzz2 pa nj) 3 zz)
(command "text" "m" (polar pzz pa nj) 3 0 zz))
;(if (/= bz "") (command "text" (polar pbz pa nj) 5 0 bz))
(setq nl (1+ nl))
);progn
(progn
(setq i 0 nj (* 8 nl))
(if (> nl 0) (setq nl (1+ nl) nj (* 8 nl)))
(if (> nl 27) (setq m_@ T nl 28)
(progn (command "text" "s" "st" (polar pmc1 pa nj) 3.5 0 mc)
(setq nl (1+ nl))
));if
));if
(if (and (= nl 28) (< ilong il)) (progn
(setq ny (1+ ny))
(if (= 0 (rem (1- ny) 4)) (setq pt (polar pt1 (* pi 0.5) 317) pt1 pt) (setq pt (polar pt 0 220)))
(inse)));if
);foreach
;(foreach pz2 p_ny1b (command "text" "s" "n" "m" pz2 3.5 0 (itoa ny)))
(command "textstyle" "standard")
(prompt "\n 材料表生成完毕! OK!")
(grtext -1 (strcat "材料表生成完毕,共" (itoa ny) "页,正在进行重生成!"))
(command "scale" "w" ptr ptl "" ptsc k "")
(command "zoom" "e" "zoom" "0.9x")
(command "view" "s" "mjview")
(grtext)
(setvar "osmode" ivar)
(princ)
)
;------------
;Main funtion.
(defun ddclb_main ()
(setq ivar (getvar "osmode"))
(setvar "cmdecho" 1) (setq m11 1)
(if (and (= 'LIST (type (setq n (read (getvar "users3"))))) (= 3 (length n)))
(setq clbgc (nth 0 n) clbbt (nth 1 n) clbth (nth 2 n))
(setq clbgc "" clbth "" clbbt ""));if
(setq dcl_id (load_dialog "ddclb.dcl"))
(if (not (new_dialog "dclbt" dcl_id))
(progn
(alert "无法打开材料表对话框,\n请检查ddclb.dcl文件路径是否正确!")
(exit)
));if
(set_tile "clb_gc" clbgc) (set_tile "clb_bt" clbbt) (set_tile "clb_th" clbth)
(mode_tile "clb_gc" 2) (mode_tile "clb_gc" 3)
(action_tile "openfile" "(do_open)")
(action_tile "bas_1" "(setq m10 1)")
(action_tile "bas_2" "(setq m10 0)")
(action_tile "clb_gc" "(setq clbgc $value)") (action_tile "clb_bt" "(setq clbbt $value)")
(action_tile "clb_th" "(setq clbth $value)")
(action_tile "sel1" "(setq m11 0) (mode_tile \"clb_gc\" 1) (mode_tile \"clb_bt\" 1) (mode_tile \"clb_th\" 1) (mode_tile \"bas_1\" 1) (mode_tile \"bas_2\" 1)")
(action_tile "sel2" "(setq m11 1) (mode_tile \"clb_gc\" 0) (mode_tile \"clb_bt\" 0) (mode_tile \"clb_th\" 0) (mode_tile \"bas_1\" 0) (mode_tile \"bas_2\" 0)")
(action_tile "accept" "(checkda)")
(action_tile "cancel" "(done_dialog 0)")
(if (= 1 (start_dialog)) (progn
(if (= m11 0) (clb) (dclb))
));if
)
(ddclb_main)
)2[/COLOR] |
|