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/>&nbsp;&nbsp;&nbsp;&nbsp;(/ PT1 PT2 S1 ANG D PT3 PT4)<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; (princ<br/>&nbsp;&nbsp;&nbsp;&nbsp;"<span class="es0">\n框选剪切"</span>)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; (if&nbsp; &nbsp; &nbsp; &nbsp; (and<br/>&nbsp;&nbsp;&nbsp;&nbsp;(setq PT1 (getpoint<br/>&nbsp;&nbsp;&nbsp;&nbsp;"<span class="es0">\n第一角点: "</span>))<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq PT2 (getcorner PT1 " &gt;&gt;&gt;第二角点: "))<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; )<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; (progn<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;;;绘制临时边界<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(command<br/>&nbsp;&nbsp;&nbsp;&nbsp;"_rectang" PT1 PT2)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq S1 (entlast))<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;;;计算边界内的四个角点<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq ANG(+ pi&nbsp;(angle PT1 PT2))<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;D&nbsp; &nbsp;(distance PT1 PT2)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;D&nbsp; &nbsp;(* D 1e-2)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;PT1 (polar PT1 ANG D)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;PT2 (polar PT2 (+ ANG pi) D)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;PT3 (list<br/>&nbsp;&nbsp;&nbsp;&nbsp;(car PT1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;(cadr PT2))<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;PT4 (list<br/>&nbsp;&nbsp;&nbsp;&nbsp;(car PT2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;(cadr PT1))<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;;;强力剪切<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(repeat<br/>&nbsp;&nbsp;&nbsp;&nbsp;10<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (command<br/>&nbsp;&nbsp;&nbsp;&nbsp;"_.trim" S1 ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;"f" PT1 PT3 PT2 PT4 PT1 ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;"")<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(command<br/>&nbsp;&nbsp;&nbsp;&nbsp;"_.erase" "all" "r"&nbsp;"w" PT1 PT2 "")<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;;;删去临时边界<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(command<br/>&nbsp;&nbsp;&nbsp;&nbsp;"_.erase" S1 "")<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; )<br/><br/></div></li><li class="li2"><div class="de2">&nbsp; &nbsp; )<br/><br/></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; (princ)<br/><br/></div></li><li class="li1"><div class="de1">)<br/>&nbsp;&nbsp;&nbsp;&nbsp;;_结束 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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;是什么意思?</p><p>&nbsp;&nbsp; "_.trim" S1 ""<br/>&nbsp;&nbsp;&nbsp; "f" PT1 PT3 PT2 PT4 PT1 ""<br/>&nbsp;&nbsp;&nbsp; "")</p><p>查遍资料也没找出TRIM居然有F这个豆豆,什么意思?&nbsp; </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 (/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aa&nbsp;&nbsp;&nbsp;&nbsp; oldgroup&nbsp;&nbsp;&nbsp;&nbsp; oldcmd oldblip&nbsp; oldsnap<br/>&nbsp;&nbsp;en&nbsp;&nbsp;&nbsp;&nbsp; dp&nbsp;&nbsp;&nbsp;&nbsp; az&nbsp;&nbsp;&nbsp;&nbsp; px&nbsp;&nbsp;&nbsp;&nbsp; p1&nbsp;&nbsp;&nbsp; ss1&nbsp;&nbsp; ss2&nbsp; sc<br/>&nbsp;&nbsp;en1&nbsp;&nbsp;&nbsp; az1&nbsp;&nbsp;&nbsp; p2&nbsp;&nbsp;&nbsp;&nbsp; pn1&nbsp;&nbsp;&nbsp; pn2&nbsp;&nbsp;&nbsp; px1 pxmax<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (setvar "LUPREC" 8)<br/>&nbsp; (setq oldgroup (getvar "pickstyle"))&nbsp;;保存编组开关<br/>&nbsp; (setvar "pickstyle" 0)&nbsp;&nbsp;;关闭编组<br/>&nbsp; (setq oldcmd (getvar "cmdecho"))&nbsp;;保存控制 command 函数运行期间,AutoCAD 是否回显提示和输入<br/>&nbsp; (setvar "cmdecho" 0)&nbsp;&nbsp;&nbsp;;关闭command 函数运行期间,AutoCAD 回显提示和输入<br/>&nbsp; (setq oldblip (getvar "blipmode"))&nbsp;;保存控制点标记<br/>&nbsp; (setvar "blipmode" 0)&nbsp;&nbsp;&nbsp;;关闭点标记<br/>&nbsp; (setq oldsnap (getvar "osmode"))&nbsp;;保存对象捕捉方式<br/>&nbsp; (setvar "osmode" 0)&nbsp;&nbsp;&nbsp;;关闭对象捕捉式<br/>&nbsp; (while<br/>&nbsp;&nbsp;&nbsp; (or&nbsp;(= (if (= (setq en (nentselp "\n选择作为剪切边界的闭合多段线:"))<br/>&nbsp;&nbsp;&nbsp; nil<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq aa "空选择!")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; "空选择!"<br/>&nbsp;)<br/>&nbsp;(= (if (/= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq aa "类型错误!")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; "类型错误!"<br/>&nbsp;)<br/>&nbsp;(= (if (and (/= (cdr (assoc 70 (entget (car en)))) 129)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (/= (cdr (assoc 70 (entget (car en)))) 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq aa "线段不闭合!")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; "线段不闭合!"<br/>&nbsp;)<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp; (alert (strcat "选择错误-" aa ",重新选择!"))<br/>&nbsp; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;选择控制<br/>&nbsp; (setq ent (car en))<br/>&nbsp; (setvar "osmode" oldsnap)<br/>&nbsp; (setvar "osmode" 16383)<br/>&nbsp; (setq dp (getpoint "\n请选择一点作为剪切基点......."))<br/>&nbsp; (setvar "osmode" 0)<br/>&nbsp; (setq az (entget (car en)))<br/>&nbsp; (setq px (list))<br/>&nbsp; (while (assoc 10 az)<br/>&nbsp;&nbsp;&nbsp; (setq p1 (cdr (assoc 10 az)))<br/>&nbsp;&nbsp;&nbsp; (setq az (cdr (member (assoc 10 az) az)))<br/>&nbsp;&nbsp;&nbsp; (setq px (cons p1 px))<br/>&nbsp; )<br/>&nbsp; (setq pxmax(list<br/>&nbsp;&nbsp;&nbsp; (apply 'mapcar (cons 'min px))<br/>&nbsp;&nbsp;&nbsp; (apply 'mapcar (cons 'max px))<br/>&nbsp; ))<br/>&nbsp; (command "zoom" "w" (car pxmax) (cadr pxmax))<br/>&nbsp; (setq ss (ssget "cp" px))<br/>&nbsp; (vl-cmdf "copy" ss "" dp pause)<br/>&nbsp; (setq dp1 (getvar "lastpoint"))<br/>&nbsp; (vl-cmdf "copy" en "" dp dp1)<br/>&nbsp; (setq en (entlast))<br/>&nbsp; (print "\n正在剪切复制选中的图形,请稍侯......")<br/>&nbsp; (setq px (list))<br/>&nbsp; (while (assoc 10 az)<br/>&nbsp;&nbsp;&nbsp; (setq p1 (cdr (assoc 10 az)))<br/>&nbsp;&nbsp;&nbsp; (setq az (cdr (member (assoc 10 az) az)))<br/>&nbsp;&nbsp;&nbsp; (setq px (cons p1 px))<br/>&nbsp; )<br/>&nbsp; (setq sc en)<br/>&nbsp; (command "offset" 0.1 sc dp "")<br/>&nbsp; (setq en1 (entlast))<br/>&nbsp; (setq az1 (entget en1))<br/>&nbsp; (setq px1 (list))<br/>&nbsp; (while (assoc 10 az1)<br/>&nbsp;&nbsp;&nbsp; (setq p2 (cdr (assoc 10 az1)))<br/>&nbsp;&nbsp;&nbsp; (setq az1 (cdr (member (assoc 10 az1) az1)))<br/>&nbsp;&nbsp;&nbsp; (setq px1 (cons p2 px1))<br/>&nbsp; )<br/>&nbsp; (setq px1 (cons (car px1) (reverse px1)))<br/>&nbsp; (command "erase" en1 "")<br/>&nbsp; (while (setq pn1 (car px1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pn2 (cadr px1)<br/>&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (command "trim" en "" "f" pn1 pn2 "" "")<br/>&nbsp;&nbsp;&nbsp; (if&nbsp;(setq del (ssget "f" (list pn1 pn2)))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (command "erase" del "")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq px1 (cdr px1))<br/>&nbsp; )<br/>&nbsp; (setvar "LUPREC" 8)<br/>&nbsp; (setvar "pickstyle" oldgroup)<br/>&nbsp; (setvar "cmdecho" oldcmd)<br/>&nbsp; (setvar "blipmode" oldblip)<br/>&nbsp; (setvar "osmode" oldsnap)<br/>&nbsp; (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>
页: [1] 2 3 4
查看完整版本: [求助]一张大的底图,如何快速裁切出其中一块矩形区域另存?