变更PRO/E转出DWG图档的图层,但转换速度太慢,看大家有没有什么办法
<p>变更PRO/E转出DWG图档的图层,但程式转换速度太慢,看大家有没有什么办法可以提高一下运算速度.我是在2007 环境下使用.</p><p>;;; p-e.lsp<br/>;;;--- 变更PRO/E图层,不能对图块转换.<commnad: p-e> ---<br/>;;;*******************************************<br/>(DEFUN new_lay (lay coL lt / chk_lay)<br/> (setq chk_lay (tblsearch "layer" lay))<br/> (if (= chk_lay nil)<br/> (command "layer" "new" lay "c" coL lay "lt" lt lay "")<br/> )<br/>)<br/>;;;*******************************************<br/>(DEFUN CH_LAY (ob lay)<br/> (command "Change" ob "" "p" "c" "bylayer" "LT" "bylayer" "la" lay "")<br/>)<br/>;;;*******************************************</p><p>(DEFUN c:p-e(/ c_lay obj n en type0 type62 type6 hat p40 cen hid pha sec dim cl)<br/> ;(%%time)<br/> (setvar "cmdecho" 0)<br/> (setq c_lay (getvar "clayer"))<br/>;;; ------------ 新建proe图层 -----------------------------<br/> (setq hat "剖面线层")<br/> (setq p40 "proe-40")<br/> (setq cen "中心线层")<br/> (setq hid "短虚线层")<br/> (setq pha "proe-PHA")<br/> (setq SEC "proe-sec")<br/> (setq dim "尺寸线层")<br/> (setq cl "0")</p><p> (new_lay hat 40 "Continuous")<br/> (new_lay p40 130 "phantom")<br/> (new_lay cen 1 "center")<br/> (new_lay hid 200 "hidden")<br/> (new_lay pha 140 "phantom")<br/> (new_lay SEC 150 "phantom")<br/> (new_lay dim 4 "Continuous")<br/>;;;;****************************************<br/> (prompt "\n 请指定转换PRO/E图层的范围")<br/> (setq obj (ssget))<br/> (if (/= obj nil)<br/> (progn</p><p>;;; ------------- 循环判断并更改proe图层 -------------</p><p> (setq n 0)<br/> (prompt "\n正在转换PRO/E的图层,可能需要几秒到几分钟,在计算过程中请等待......\n")<br/> (repeat (sslength obj)<br/> (setq en (ssname obj n))<br/> (setq type0 (cdr (assoc 0 (entget en))))<br/> (setq type62 (cdr (assoc 62 (entget en))))<br/> (setq type6 (cdr (assoc 6 (entget en))))<br/> ;(setq type8 (cdr (assoc 8 (entget en))))</p><p>;;; ------------ 判断并更改到 0 图层 -------------<br/> (if (= type62 7)<br/> (CH_LAY en cl)<br/> )</p><p>;;; ------------ 判断并更改到PROE-HAT图层 -------------<br/> (if<br/> (and (and (= type0 "LINE") (= type62 2))<br/> (= type6 "Continuous")<br/> )<br/> (CH_LAY en hat)<br/> )<br/>;;;------------ 判断并更改到PROE-40图层 ---------------<br/> (if (= type62 40)<br/> (CH_LAY en p40)<br/> )<br/>;;;------------ 判断并更改到PROE-cen图层 --------------<br/> (if (and (= type6 "CENTER") (= type62 2))<br/> (CH_LAY en cen)<br/> )<br/>;;;------------ 判断并更改到短虚线层图层 --------------<br/> (if (or (or (= type6 "HIDDEN") (= type62 8))<br/> (and (= type6 "HIDDEN") (= type62 7))<br/> )<br/> (CH_LAY en hid)<br/> )<br/>;;;------------ 判断并更改到PROE-pha图层 ----------------<br/> (if (= type6 "PHANTOM")<br/> (CH_LAY en pha)<br/> )<br/>;;;------------ 判断并更改到PROE-sec图层 --------------<br/> (if (and (= type6 "CENTER") (= type62 9))<br/> (CH_LAY en sec)<br/> )<br/>;;;------------ 判断并更改到PROE-dim图层 --------------<br/> (if (= type0 "DIMENSION")<br/> (progn<br/> (CH_LAY en dim)<br/> (command "dimstyle" "apply" en "")<br/> )<br/> )<br/>;;;------------ one end ------------------------------- <br/> (setq n (1+ n))<br/> )<br/> (print "恭喜你已完成改变PRO/E图层")<br/> (print)<br/> )<br/> )<br/>(setvar "clayer" c_lay)<br/> (princ)<br/>)<br/></p> 慢的的原因有可能是command用的多 看了楼主的程序,主要是循环中执行command造成的。下面是改写的程序:要想程序快,就要少用变量,少调用子程序。因为从变量中取数和调用子程序都要消耗时间,虽然现在计算机速度快了,可以忽略不计,但架不住积少成多。
(DEFUN c:p-e(/ c_lay ss p1 p2 hat p40 cen hid pha sec dim cl)
;(%%time)
(setvar "cmdecho" 0)
(setq c_lay (getvar "clayer"))
;;; ------------新建proe图层 -----------------------------
(setq hat "剖面线层")
(setq p40 "proe-40")
(setq cen "中心线层")
(setq hid "短虚线层")
(setq pha "proe-PHA")
(setq SEC "proe-sec")
(setq dim "尺寸线层")
(setq cl"0")
(new_lay hat 40"Continuous")
(new_lay p40 130 "phantom")
(new_lay cen 1 "center")
(new_lay hid 200 "hidden")
(new_lay pha 140 "phantom")
(new_lay SEC 150 "phantom")
(new_lay dim 4 "Continuous")
;;;;****************************************
(prompt "")
(setq p1 (getpoint "\n请指定转换PRO/E图层的范围")
p2 (getcorner p1 "\n另一角点 :"))
;;; ------------- 循环判断并更改proe图层 -------------
(prompt "\n正在转换PRO/E的图层,请稍候...\n")
(if (setq ss (ssget "W" p1 p2 '((62 . 7))))
(command "chprop" ss "" "LA" "0" "")
)
(if (setq ss (ssget "W" p1 p2 '((0 . "LINE") (62 . 2) (6 . "Continuous"))))
(command "chprop" ss "" "LA" "剖面线层" "")
)
(if (setq ss (ssget "W" p1 p2 '((6 . "CENTER") (62 . 2))))
(command "chprop" ss "" "LA" "中心线层" "")
)
(if (setq ss (ssget "W" p1 p2 '((6 . "HIDDEN") (-4 . "<or") (62 . 8) (62 . 7) (-4 . "or>"))))
(command "chprop" ss "" "LA" "短虚线层" "")
)
(if (setq ss (ssget "W" p1 p2 '((6 . "PHANTOM"))))
(command "chprop" ss "" "LA" "proe-PHA" "")
)
(if (setq ss (ssget "W" p1 p2 '((0 . "DIMENSION"))))
(command "chprop" ss "" "LA" "尺寸线层" "" "dimstyle" "apply" ss "")
)
(print "恭喜你已完成改变PRO/E图层")
(setvar "clayer" c_lay)
(princ)
)
感谢 ZZXXQQ 的指正,现在速度提高非常多,但对于选择有几万图元的集还是不行,但速度已经比以前好很多了。我再试一下用"entmod"看会不会更快。 最近在弄一个图层转换工具,前来学习,
页:
[1]