mmmmmm
发表于 2004-4-13 18:45:00
不用那么麻烦,使用ExpressTool命令chspace
citykunan
发表于 2004-4-14 08:26:00
chspace我也用过,是把model中的东西复制到pspace中,这样model的东西就没有了。程序我正在想办法编,应该快好了。
citykunan
发表于 2004-4-14 10:56:00
(defun C:M_VIEW (/ VCTRX VCTRY LPT RPT ang dis any_point HOLDECHO HOLDOSMODE ss_i<BR>i a len_list first_a first_ent nlist_list first_nlist_list first_nlist_list_backup<BR>first_point first_point BOX WDXF XP W10 W12 W40 W41 W69 SS first_poi <BR>final_list_1 final_list first_one rt lb<BR> )
(defun DO_IT (CEN)<BR> (setq VCTRX (car CEN))<BR> (setq VCTRY (cadr CEN))<BR> (setq<BR> LPT (list (- VCTRX (/ W40 2.0)) (- VCTRY (/ W41 2.0)))<BR> )<BR> (setq<BR> RPT (list (+ VCTRX (/ W40 2.0)) (+ VCTRY (/ W41 2.0)))<BR> )<BR> );得出矩形两个角点坐标<BR> (defun Do_any_point (poi)<BR> (setq ang (angle w10 poi))<BR> (setq dis (distance w10 poi))<BR> (setq any_point (polar w12 ang (/ dis xp)))<BR> ) ;得到cp框的选择范围。后来想想没有必要。<BR> (setq HOLDECHO (getvar "cmdecho"))<BR> (setq HOLDOSMODE (getvar "osmode"))<BR> (setvar "cmdecho" 0)<BR> (setvar "osmode" 0)<BR> (command "_.undo" "be")<BR> (command "_.PSPACE")<BR> (leo_sc)<BR> ;(setq A (car (entsel "\nSelect Viewport: ")))<BR> (setq ss_i (ssget '((0 . "LWPOLYLINE,VIEWPORT"))))<BR> (setq i 0)<BR> (while (< i (sslength ss_i))<BR> (setq a (ssname ss_i i))<BR> <BR> <BR> <BR> ;(setq len_list (length nlist_list ))<BR> (setq first_a a)<BR> (setq first_ent (cdr (assoc 0 (entget a))) )<BR> (if (= first_ent "LWPOLYLINE")<BR> (progn<BR> (setq nlist_list (MASSOC 10 (entget a)))<BR> (setq first_nlist_list nlist_list)<BR> (setq first_nlist_list_backup first_nlist_list)<BR> (command "_.pline" (setq first_point (car nlist_list)))<BR> (while (setq nlist_list (cdr nlist_list))<BR> (command (car nlist_list))<BR> );enf while<BR> (command first_point "")<BR> (setq BOX (entlast))<BR> (setq a (cdr (assoc 330 (entget a))));得到附加的viewport组码<BR> );end progn<BR> );end if <BR> (progn<BR> (setq WDXF (entget A))<BR> (setq XP (/ (cdr (assoc 41 WDXF)) (cdr (assoc 45 WDXF))));-------45号码是什么用的?好像是个比例因子,我研究下来发现可以得到viewport的比例<BR> ;经多次研究发现41号码除以45号码总能得到viewport的比例<BR> (setq W10 (cdr (assoc 10 WDXF)));viewport视图的中点<BR> (setq W12 (cdr (assoc 12 WDXF)));wcs下的目标点<BR> (setq W40 (cdr (assoc 40 WDXF)));视图的高度<BR> <BR> <BR> (setq W41 (cdr (assoc 41 WDXF)));视图的宽度<BR> (setq W69 (cdr (assoc 69 WDXF)));app:视口的表示数字<BR> (DO_IT W10)<BR> <BR> (if (= first_ent "VIEWPORT")<BR> (progn <BR> (command "_.rectang" LPT RPT)<BR> (setq BOX (entlast))<BR> )<BR> )<BR> <BR> (command "zoom" LPT RPT)<BR> (setq W40 (/ W40 XP)) <BR> (setq W41 (/ W41 XP))<BR> (command "_.MSPACE")<BR> (setvar "cvport" W69); <BR> (command "_.ucs" "v"); <BR> (DO_IT W12);得到相应大小的矩形框。<BR> (if (= first_ent "VIEWPORT")<BR> (setq SS (ssget "c" RPT LPT))<BR> (progn<BR> (while (setq first_poi (car first_nlist_list))<BR> (setq final_list_1 (list (Do_any_point first_poi)))<BR> (setq final_list (append final_list_1 final_list))<BR> (setq first_nlist_list (cdr first_nlist_list))<BR> );end while<BR> (setq SS (ssget "cp" final_list))<BR> );end progn<BR> )<BR> (if SS<BR> (progn<BR> (setq AA (rtos (* (getvar "CDATE") 1E8)));做块名<BR> (command "_.block" AA W12 SS "")<BR> (command "_.oops");undo erase<BR> (command "_.pspace")<BR> (command "_.insert" AA W10 XP "" "")<BR> (if (= first_ent "VIEWPORT")<BR> (command "_.xclip" (entlast) "" "N" "S" BOX)<BR> (progn <BR> (command "_.xclip" (entlast) "" "n" "p" (setq first_one (car first_nlist_list_backup)))<BR> (while (setq first_nlist_list_backup (cdr first_nlist_list_backup))<BR> (command (car first_nlist_list_backup))<BR> );end while<BR> (command first_one "")<BR> );progn<BR> );end if<BR> <BR> )<BR> );end if<BR> (command "_.pspace")<BR> <BR> (command "_.ERASE" A "")<BR> <BR> <BR> );end progn<BR> <BR> (command "zoom" rt lb)<BR> (setq i (+ i 1))<BR>);end whlie<BR> <BR> (setvar "osmode" HOLDOSMODE)<BR> (setvar "cmdecho" HOLDECHO)<BR> (command "_.undo" "e")<BR> (princ)<BR>)
;可以做参考,取得绘图窗口坐标<BR>(defun leo_sc (/ ctr size SCREEN SCALE XSIZE) <BR> (command "_.UCS" "V") <BR> (setq CTR (getvar "VIEWCTR")) <BR> (setq SIZE (getvar "VIEWSIZE")) <BR> (setq SCREEN (getvar "SCREENSIZE")) <BR> (setq SCALE (/ (car SCREEN) (cadr SCREEN))) <BR> (setq XSIZE (* SCALE SIZE)) <BR> (setq RT (list (+ (car CTR) (/ XSIZE 2)) (+ (cadr CTR) (/ SIZE 2)))) <BR> (setq LB (list (- (car CTR) (/ XSIZE 2)) (- (cadr CTR) (/ SIZE 2)))) <BR> ;(command "_.line" RT LB "") <BR> ;(command "_.UCS" "P") <BR> (princ) <BR>)
<BR>;得到同一dxf码的多个值,如 (MASSOC 10 (entget (car (entsel)))),可以得到pline的多个节点<BR>(defun massoc (key alist / x nlist)<BR>(foreach x alist<BR>(if (eq key (car x))<BR>(setq nlist (cons (cdr x) nlist))<BR>)<BR>)<BR>(reverse nlist)<BR>)
<BR> <BR>(princ)<BR>(prompt "\nType M_VIEW to run")<BR>(princ)<BR>
程序基本编完了,但是还有一个问题,好像只能单选,复选后会在成功转换完第一个viewport后出现; error: bad argument type: numberp: nil,不知是什么原因?望版主指教。谢谢。
龙龙仔
发表于 2004-4-14 12:46:00
本帖最后由 作者 于 2004-4-14 15:25:34 编辑 <br /><br /> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3>當耐心用完我會給你寫一個<FONT face="Times New Roman">,</FONT>但不是現在 (寫好了!但沒有詳細測試及整理)</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><FONT face="Times New Roman">1.</FONT>看看它與預期有甚麼不一樣<FONT face="Times New Roman">(sslength SS_I)</FONT></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><FONT face="Times New Roman">2.</FONT>注意<FONT face="Times New Roman">:DXF 69 </FONT>不能為<FONT face="Times New Roman">1 </FONT></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman" size=3>3. (and (= FIRST_ENT "LWPOLYLINE")</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><FONT size=3><SPAN style="mso-spacerun: yes"> (= (cdr (assoc 0 (entget (cdr (assoc 330 (entget A))))))</FONT></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><FONT size=3><SPAN style="mso-tab-count: 1"> "VIEWPORT"</FONT></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><FONT size=3><SPAN style="mso-spacerun: yes"> )</FONT></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 12pt; mso-char-indent-count: 1.0"><FONT face="Times New Roman" size=3>)</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><FONT face="Times New Roman">4</FONT>得到<FONT face="Times New Roman">cp</FONT>框的選擇範圍。後來想想沒有必要。</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><FONT face="Times New Roman">-></FONT>給你發現了。找它的包圍盒。<FONT face="Times New Roman"> 8-) "好像連包圍盒也不用" 8-)</FONT></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman" size=3>5…….</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman" size=3>6……..</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 12pt; mso-char-indent-count: 1.0"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face="Times New Roman" size=3> </FONT></o:p>
citykunan
发表于 2004-4-14 13:46:00
谢谢龙版主,我学到了很多。
好像<FONT face="Times New Roman" size=3>(sslength SS_I)的值总是0,奇怪。我做了单选的程序用(ENTSEL)去选就没问题了。</FONT>
龙龙仔
发表于 2004-4-16 16:00:00
不用理會LWPOLYLINE的頂點(不然有圓弧的LWPOLYLINE你弄得出來嗎?),只要把DXF 330碼去掉,再用ENTMAKE重建LWPOLYLINE即可.
citykunan
发表于 2004-4-16 20:55:00
版主的提示我有些明白了,明后两日到外地出差,星期一回公司写,班主再给点时间,我应该能写出。谢谢版主。
citykunan
发表于 2004-4-20 18:23:00
如今可以实现矩形和pline的viewport的复选转换。在编程中我发现一个问题。就是当选择附有viewport的LWPOLYLINE时,哪怕是点选(单选),仍然会显示有两个物体(select object: 2 found),我不知道为什么,但这会给程序带来麻烦。我猜想可能一个是LWPOLYLINE而另一个是viewport,在多次程序的调试后,我加了一条语句便可成了:
(if (and (= FIRST_ENT "LWPOLYLINE")<BR> (= (cdr (assoc 0 (entget (cdr (assoc 330 (entget A)))))) "VIEWPORT")<BR> )<BR> (progn<BR> (setq a (cdr (assoc 330 (entget a))));得到附加的viewport组码<BR> (entmake (vl-remove-if '(lambda (X) (= 330 (car X))) (entget first_a)))<BR> (setq BOX (entlast))<BR> (SETQ i (+ i 1)) ;我加了这句,想跳过LWPOLYLINE后的选择集中的一个物体<BR> );end progn<BR> );end if
其中(SETQ i (+ i 1)) 是为了跳过选择集中的一个东西,结果程序可运行了,但我不知道是为什么,还望高手指点,进一步完善程序。谢谢龙版主的关心。自己通过这个程序学到了不少东西。
龙龙仔
发表于 2004-4-21 09:56:00
本帖最后由 作者 于 2004-4-21 12:06:25 编辑 <br /><br />
<P style="WORD-BREAK: break-all; LINE-HEIGHT: 12pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: SimSun; mso-fareast-font-family: 新細明體">1.<FONT face=新細明體>這應是</FONT>Autocad<FONT face=新細明體>本身的規則吧</FONT>(<FONT face=新細明體>對我也是新發現</FONT>)! 8-)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">2.把函數leo_sc刪除吧!不是有do_it函數了嗎?<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">3.當 (setq ss_i (ssget '((0 . "LWPOLYLINE,VIEWPORT")))),回應all時會出錯的,<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"> a.</SPAN>提示過 w69 > 1 <o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"> b.</SPAN>對沒有附帶的LWPOLYLINE會出錯<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 9pt; mso-char-indent-count: 1.0">c.……<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">4.反向操作,從VIEWPORT中也有DXF340碼記錄了VIEWPORT是由某LWPOLYLINE建成<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 9pt; mso-char-indent-count: 1.0">(程序可否利用這點再寫一次,有點要求過多了嗎?)。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 9pt; mso-char-indent-count: 1.0"><o:p> </o:p>
<P style="WORD-BREAK: break-all; LINE-HEIGHT: 12pt">PS:[<FONT face=新細明體>利用這點再寫一次</FONT>]-----<FONT face=新細明體>我寫好了</FONT>!<o:p></o:p>
</SPAN>
citykunan
发表于 2004-4-21 14:23:00
想改进一下,可是又遇到了困难,将程序附上,请高手看看。