nabworm
发表于 2007-8-23 09:04:00
[求助]一张大的底图,如何快速裁切出其中一块矩形区域另存?
<p>[求助]一张大的底图,如何快速裁切出其中一块矩形区域另存?</p><p>情况:底图很大,多段线、样条线、矩形、直线均有</p><p>目的:标准的矩形区域,不要有多余的边边角角</p>
sony-lin
发表于 2007-8-23 22:49:00
本帖最后由 作者 于 2007-8-23 23:04:57 编辑 <br /><br /> <p>使用 矩形(trim)</p><p>利用图点两点 自动得到rectang</p><p>然后向外offset rectang</p><p>代码如下:<br/><br/></p><ol><li class="li1"><div class="de1">(defun C:JJ<br/> (/ PT1 PT2 S1 ANG D PT3 PT4)<br/><br/></div></li><li class="li2"><div class="de2"> (princ<br/> "<span class="es0">\n框选剪切"</span>)<br/><br/></div></li><li class="li1"><div class="de1"> (if (and<br/> (setq PT1 (getpoint<br/> "<span class="es0">\n第一角点: "</span>))<br/><br/></div></li><li class="li1"><div class="de1"> (setq PT2 (getcorner PT1 " >>>第二角点: "))<br/><br/></div></li><li class="li1"><div class="de1"> )<br/><br/></div></li><li class="li1"><div class="de1"> (progn<br/><br/></div></li><li class="li2"><div class="de2"> ;;绘制临时边界<br/><br/></div></li><li class="li1"><div class="de1"> (command<br/> "_rectang" PT1 PT2)<br/><br/></div></li><li class="li1"><div class="de1"> (setq S1 (entlast))<br/><br/></div></li><li class="li1"><div class="de1"> ;;计算边界内的四个角点<br/><br/></div></li><li class="li1"><div class="de1"> (setq ANG(+ pi (angle PT1 PT2))<br/><br/></div></li><li class="li2"><div class="de2"> D (distance PT1 PT2)<br/><br/></div></li><li class="li1"><div class="de1"> D (* D 1e-2)<br/><br/></div></li><li class="li1"><div class="de1"> PT1 (polar PT1 ANG D)<br/><br/></div></li><li class="li1"><div class="de1"> PT2 (polar PT2 (+ ANG pi) D)<br/><br/></div></li><li class="li1"><div class="de1"> PT3 (list<br/> (car PT1)<br/> (cadr PT2))<br/><br/></div></li><li class="li2"><div class="de2"> PT4 (list<br/> (car PT2)<br/> (cadr PT1))<br/><br/></div></li><li class="li1"><div class="de1"> )<br/><br/></div></li><li class="li1"><div class="de1"> ;;强力剪切<br/><br/></div></li><li class="li1"><div class="de1"> (repeat<br/> 10<br/><br/></div></li><li class="li1"><div class="de1"> (command<br/> "_.trim" S1 ""<br/> "f" PT1 PT3 PT2 PT4 PT1 ""<br/> "")<br/><br/></div></li><li class="li2"><div class="de2"> )<br/><br/></div></li><li class="li1"><div class="de1"> (command<br/> "_.erase" "all" "r" "w" PT1 PT2 "")<br/><br/></div></li><li class="li1"><div class="de1"> ;;删去临时边界<br/><br/></div></li><li class="li1"><div class="de1"> (command<br/> "_.erase" S1 "")<br/><br/></div></li><li class="li1"><div class="de1"> )<br/><br/></div></li><li class="li2"><div class="de2"> )<br/><br/></div></li><li class="li1"><div class="de1"> (princ)<br/><br/></div></li><li class="li1"><div class="de1">)<br/> ;_结束 defun</div></li></ol>
nabworm
发表于 2007-8-24 10:00:00
牛人,研究 中
nabworm
发表于 2007-8-24 10:09:00
<p>时灵时不灵</p><p>有时会出些奇怪的问题,剪切得只剩几根线?</p><p>不知道是因为哪回事</p><p>还有图大的时候就会很慢(先截个大致范围后处理就行了)</p><p></p><p>总之很PF了</p>
nabworm
发表于 2007-8-24 10:17:00
<p>repeat 10 ;是什么意思?</p><p> "_.trim" S1 ""<br/> "f" PT1 PT3 PT2 PT4 PT1 ""<br/> "")</p><p>查遍资料也没找出TRIM居然有F这个豆豆,什么意思? </p><p></p><p>还真是大牛人啊</p>
sony-lin
发表于 2007-8-24 14:28:00
<p>repeat 10 这里表示10次trim</p><p>10次主要是对于多段线的</p><p>这个是不能剪接参照 和块的!!</p>
nabworm
发表于 2007-8-27 09:29:00
受教1次,继续
xgr
发表于 2007-8-30 00:08:00
本帖最后由 作者 于 2007-8-30 2:01:25 编辑 <br /><br /> <p>试试我的代码</p><p>(defun c:txjq3 (/ aa oldgroup oldcmd oldblip oldsnap<br/> en dp az px p1 ss1 ss2 sc<br/> en1 az1 p2 pn1 pn2 px1 pxmax<br/> )<br/> (setvar "LUPREC" 8)<br/> (setq oldgroup (getvar "pickstyle")) ;保存编组开关<br/> (setvar "pickstyle" 0) ;关闭编组<br/> (setq oldcmd (getvar "cmdecho")) ;保存控制 command 函数运行期间,AutoCAD 是否回显提示和输入<br/> (setvar "cmdecho" 0) ;关闭command 函数运行期间,AutoCAD 回显提示和输入<br/> (setq oldblip (getvar "blipmode")) ;保存控制点标记<br/> (setvar "blipmode" 0) ;关闭点标记<br/> (setq oldsnap (getvar "osmode")) ;保存对象捕捉方式<br/> (setvar "osmode" 0) ;关闭对象捕捉式<br/> (while<br/> (or (= (if (= (setq en (nentselp "\n选择作为剪切边界的闭合多段线:"))<br/> nil<br/> )<br/> (setq aa "空选择!")<br/> )<br/> "空选择!"<br/> )<br/> (= (if (/= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")<br/> (setq aa "类型错误!")<br/> )<br/> "类型错误!"<br/> )<br/> (= (if (and (/= (cdr (assoc 70 (entget (car en)))) 129)<br/> (/= (cdr (assoc 70 (entget (car en)))) 1)<br/> )<br/> (setq aa "线段不闭合!")<br/> )<br/> "线段不闭合!"<br/> )<br/> )<br/> (alert (strcat "选择错误-" aa ",重新选择!"))<br/> ) ;选择控制<br/> (setq ent (car en))<br/> (setvar "osmode" oldsnap)<br/> (setvar "osmode" 16383)<br/> (setq dp (getpoint "\n请选择一点作为剪切基点......."))<br/> (setvar "osmode" 0)<br/> (setq az (entget (car en)))<br/> (setq px (list))<br/> (while (assoc 10 az)<br/> (setq p1 (cdr (assoc 10 az)))<br/> (setq az (cdr (member (assoc 10 az) az)))<br/> (setq px (cons p1 px))<br/> )<br/> (setq pxmax(list<br/> (apply 'mapcar (cons 'min px))<br/> (apply 'mapcar (cons 'max px))<br/> ))<br/> (command "zoom" "w" (car pxmax) (cadr pxmax))<br/> (setq ss (ssget "cp" px))<br/> (vl-cmdf "copy" ss "" dp pause)<br/> (setq dp1 (getvar "lastpoint"))<br/> (vl-cmdf "copy" en "" dp dp1)<br/> (setq en (entlast))<br/> (print "\n正在剪切复制选中的图形,请稍侯......")<br/> (setq px (list))<br/> (while (assoc 10 az)<br/> (setq p1 (cdr (assoc 10 az)))<br/> (setq az (cdr (member (assoc 10 az) az)))<br/> (setq px (cons p1 px))<br/> )<br/> (setq sc en)<br/> (command "offset" 0.1 sc dp "")<br/> (setq en1 (entlast))<br/> (setq az1 (entget en1))<br/> (setq px1 (list))<br/> (while (assoc 10 az1)<br/> (setq p2 (cdr (assoc 10 az1)))<br/> (setq az1 (cdr (member (assoc 10 az1) az1)))<br/> (setq px1 (cons p2 px1))<br/> )<br/> (setq px1 (cons (car px1) (reverse px1)))<br/> (command "erase" en1 "")<br/> (while (setq pn1 (car px1)<br/> pn2 (cadr px1)<br/> )<br/> (command "trim" en "" "f" pn1 pn2 "" "")<br/> (if (setq del (ssget "f" (list pn1 pn2)))<br/> (command "erase" del "")<br/> )<br/> (setq px1 (cdr px1))<br/> )<br/> (setvar "LUPREC" 8)<br/> (setvar "pickstyle" oldgroup)<br/> (setvar "cmdecho" oldcmd)<br/> (setvar "blipmode" oldblip)<br/> (setvar "osmode" oldsnap)<br/> (princ)<br/>)<br/>怎么加载不用多说吧!</p><p>图形剪切边界接触哦到块的话,请先分解块,剪切出来的图形复制在本图内,</p><p>如果要另存,请用带基点复制到新图。</p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p>
nabworm
发表于 2007-8-30 09:09:00
<p>研究中</p><p>不错,非常细致</p><p>思路貌似与前例一样,就是为什么大家都知道这个TRIM有个F的用法,我却到处都查不到?</p><p>范例地图测试中,分解块的问题和我想的一样,毕竟任何块都要打散才能被VBA和VLISP操作</p><p>详细程序研究中............</p><p>继续</p>
nabworm
发表于 2007-8-30 09:31:00
<p>效果基本上可以达到商用水准了</p><p>看来我还是要进行选择集和ActiveX方面的学习呀</p><p>源码跟踪学习中...</p><p>[从鱼到渔]</p><p></p>