帐号为空 发表于 2007-4-2 11:20:00

[求助]如何:join几条线段(多线段),然后闭合这条连接后的多线段?

本帖最后由 作者 于 2007-4-2 11:23:54 编辑 <br /><br /> <p>废话一句:本人刚入门,这是我的第二个程序。既然刚入门,提问题也许很菜,但还是要提。诚请知道的人答复!深表感谢!</p><p>本人的意思:AutoLisp调用Command的“pedit”命令,使它能够完成连接几条线段,多线段,在选择几条多线段之后,使这条合成后的多线段闭合。</p><p>本人做出过不少尝试,但都失败。用到了while循环,但因为join命令本身有一个循环,所以弄了两天一直没有搞懂应该怎么办。</p><p>(defun c:pj ()<br/>&nbsp;&nbsp; &nbsp;(setvar "cmdecho" 1)<br/>&nbsp;&nbsp; &nbsp;(command "peditaccept" 1)<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; (command "pedit"&nbsp;"j" )&nbsp; ;;;调用Pedit命令,join命令<br/>&nbsp;&nbsp;&nbsp;&nbsp; (setq pl(entsel))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;;取值,<br/>&nbsp;&nbsp;&nbsp;&nbsp; (while&nbsp;pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;;如果pl存在,即如果选取了线段,则执行循环,但join本身就有一个循环<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(setq pl(entsel))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp; (command&nbsp; "c" "")&nbsp;&nbsp;&nbsp; ;;;调用闭合命令,使多线段闭合</p><p>)</p>

sdls 发表于 2019-1-25 22:44:08

linshiyin2 发表于 2010-6-2 15:45
(defun fsxm-silenceexit (/ *error*) ;无声退出 ;by fsxm&nbsp; (t (setq *error* strcat)))
(defun c:n...

8楼的程序,太好了!这个是我想要的!谢谢!

yk1216 发表于 2024-8-31 14:30:25

感谢大家的分享,学习了

luhy2008 发表于 2019-7-10 13:44:23

感谢楼上分享!赞!

caoyin 发表于 2007-4-2 13:03:00

<p>1.&nbsp;PEDIT 命令后不应该为 "j", 而应该为图元名!</p><p>2. 在这种情况下不适合用 while ,如果循环结束,它传递给command的参数就是 nil</p><p>3. 最好先获取参数然后再command</p><p>4.&nbsp;(while&nbsp;pl&nbsp;(setq pl(entsel)))为什么不直接用 ssget</p><p>5. 当你第一次&nbsp; (setq pl(entsel))&nbsp; 时,是否要将结果进行判断,是多段线还是直线,因为类型不同</p><p>&nbsp;&nbsp; 命令行参数也不一样</p><p>6. 与其这样还不如干脆这样</p><p>(defun c:pj ()<br/>&nbsp;&nbsp;&nbsp;&nbsp; (command "pedit" pause "j" pause "" "c" "")<br/>)</p>

byghbcx 发表于 2007-4-2 14:39:00

<p>(ENTSEL)返回点表,要运用(CAR (ENTSEL))才能返回图元名</p><p>要将第一次选择结果进行判断,是多段线还是直线、弧……</p><p>(defun c:pj ()<br/>&nbsp;&nbsp;&nbsp; (setvar "cmdecho" 0)<br/>&nbsp;&nbsp;&nbsp; (command "peditaccept" 1)<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; (command "pedit")&nbsp; ;;;调用Pedit命令,join命令<br/>&nbsp;&nbsp;&nbsp;&nbsp; (setq pl (car (entsel)))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;;取值,<br/>&nbsp;&nbsp;&nbsp;&nbsp; (IF pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;;如果pl存在,即如果选取了线段,则执行循环,但join本身就有一环<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PROGN<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (command pl)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if (WCMATCH (CDR (ASSOC 0 (ENTGET PL))) "*POLYLINE") (command "J") (command "Y" "J"))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq pl (SSGET))<br/>&nbsp;&nbsp; (command pl "" "C" "");;;调用闭合命令,使多线段闭合<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (setvar "cmdecho" 1)<br/>(PRINC)<br/>)</p>

帐号为空 发表于 2007-4-2 14:54:00

<p>哈哈哈哈 ~!</p><p>太好了,太谢谢了 !</p><p>根据<font face="Verdana" color="#61b713"><strong><em>caoyin</em><font color="#44bba3">大侠的提示,终于解决了问题。非常感谢!</font></strong></font></p><p><strong><font face="Verdana" color="#44bba3">依找caoyin的意见,修改如下:</font></strong></p><p>(defun c:pj ()<br/>&nbsp; (setvar "cmdecho" 1)<br/>&nbsp; (command "peditaccept" 1)&nbsp;&nbsp;&nbsp; ;;;如果是直线,则直接变为多线段从而跳过询问<br/>&nbsp; (setq pl_sel (ssget))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;;取得选择集,也就是仁兄所说,先获取参数。<br/>&nbsp; (command "pedit" "m" pl_sel "" "j" "0.01" "c" "")&nbsp;&nbsp; ;;;万事俱备,只要调用command命令即可,</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;;其中“j”前必须加上一个空格命令,<br/>&nbsp;)<br/></p><p></p><p>学习是一件很快乐的事情啊!</p><p>哈哈 ,</p>

帐号为空 发表于 2007-4-2 15:06:00

<p>刚看了三楼的提示,程序是能解决问题,可是我不太明白一些问题:</p><p>1.(command pl) 这句不知道什么作用。是相当于CAD命令行中先放入之前的选择集的意思?</p><p>2.在之前已经有了“ (command "peditaccept" 1)”这句,后面是不是(我认为是)就不用判断是直线还是多线段了?</p><p></p><p>谢谢你的答复,希望与您交流。</p>

byghbcx 发表于 2007-4-2 15:21:00

<p>(command pl)是执行PEDIT后的先择对象,</p><p>(command "peditaccept" 1)后面是不用判断是直线还是多线段了,但在ACAD2002以下版中没有这个系统变量</p>

帐号为空 发表于 2007-4-5 18:55:00

终于知道一点点了,知道返回的对象是怎么回事了。总算有一点进步了

linshiyin2 发表于 2010-6-2 15:45:00

<p><font face="Verdana">(defun fsxm-silenceexit (/ *error*) ;无声退出 ;by fsxm<br/>&nbsp; (t (setq *error* strcat))<br/>)</font></p>
<p><font face="Verdana">(defun c:n (/ ss *error*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;连接多义线<br/>(defun *error* (msg) (princ))<br/>(princ "\n连接多义线")<br/>(setq ss (ssget '((-4 . "&lt;or")<br/>(-4 . "&lt;AND") (0 . "LWPOLYLINE") (70 . 0) (-4 . "AND&gt;")<br/>(0 . "LINE")<br/>(0 . "ARC")<br/>(-4 . "or&gt;")))<br/>)<br/>(or ss (fsxm-silenceexit))<br/>(setvar "cmdecho" 0)<br/>(setvar "PEDITACCEPT" 1)<br/>(if (= (sslength ss) 1)<br/>&nbsp; (vl-cmdf "PEDIT" (ssname ss 0) "j" "all" "" "")<br/>&nbsp; (command "PEDIT" "m" "P" "" "j" "" "")<br/>)<br/>(setvar "PEDITACCEPT" 0)<br/>(princ)<br/>)</font></p>

390311997 发表于 2019-7-10 08:06:02

谢谢分享!!!!!
页: [1] 2
查看完整版本: [求助]如何:join几条线段(多线段),然后闭合这条连接后的多线段?