fanqinwei 发表于 2012-5-23 20:49:09

已经用上了,好顺手呀,谢G版了。

crazylsp 发表于 2012-5-24 11:32:53

<span class="Apple-style-span" style="background-color: orange;"><font class="Apple-style-span" color="#000080">;; 对齐<br>;; 兴趣来了,GX基础上改了下,未测试,不行再改。<br><br><br>(defun c:pldq () <br><br>;;子程序&nbsp;&nbsp;<br>;;选择集转表&nbsp;&nbsp;<br>&nbsp;&nbsp;(defun gxl-Sel-SS-&gt;List (ss / i s )&nbsp;&nbsp;<br>&nbsp; &nbsp; (if ss&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(repeat&nbsp;&nbsp;(setq i (sslength ss))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq s (cons (ssname ss (setq i (1- i))) s))&nbsp; &nbsp; )&nbsp; &nbsp; )) <br> <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;;;计算物体中心点&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(defun gxl-getboxCenter (e1 / obj minpoint maxpoint)&nbsp;&nbsp;<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(if (= 'ENAME (type e1))&nbsp;&nbsp;<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq obj (vlax-ename-&gt;vla-object e1)) <br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;;转换图元名&nbsp; &nbsp; <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq obj e1)&nbsp; &nbsp; <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (vla-GetBoundingBox obj 'minpoint 'maxpoint) <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ;取得包容图元的最大点和最小点&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (setq minpoint (vlax-safearray-&gt;list minpoint)) <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ;把变体数据转化为表&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (setq maxpoint (vlax-safearray-&gt;list maxpoint)) <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ;把变体数据转化为表&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (setq p (mapcar '+ minpoint maxpoint))&nbsp; &nbsp; <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (mapcar '(lambda (x) (* 0.5 x)) p))&nbsp;&nbsp;<br><br><br>;;主程序&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq cmdecho (getvar 'cmdecho))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq osmode (getvar 'osmode))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setvar 'osmode 0)&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setvar 'cmdecho 0)&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(princ "\n选择基准物体:")&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s1 (ssget))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(princ "\n选择要对齐物体:")&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s2 (ssget))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s1 (GXL-SEL-SS-&gt;LIST s1)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;s2 (GXL-SEL-SS-&gt;LIST s2)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;;_ 按Y从大到小排序<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s1 (mapcar '(lambda (x) (list x (GXL-GETBOXCENTER x))) s1))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s1 (vl-sort s1 '(lambda (a b) (&gt; (cadadr a) (cadadr b))) )) <br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s2 (mapcar '(lambda (x) (list x (GXL-GETBOXCENTER x))) s2))&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;(setq s2 (vl-sort s2 '(lambda (a b) (&gt; (cadadr a) (cadadr b))) )) <br><br>&nbsp; &nbsp;&nbsp; &nbsp;;_ 表长比较<br>&nbsp; &nbsp;&nbsp; &nbsp;(if&nbsp;&nbsp;(&gt; (length s1) (length s2) ) <br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq &nbsp;</font></span><span class="Apple-style-span" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Simsun; line-height: normal; font-size: medium; "><font class="Apple-style-span" color="#000080" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-wrap: break-word; ">&nbsp;&nbsp;</font></span><font class="Apple-style-span" color="#000080" style="background-color: orange; ">TMP s2 &nbsp; </font><span class="Apple-style-span" style="background-color: rgb(244, 164, 96);"><font class="Apple-style-span" color="#ffa500">&nbsp;</font><span class="Apple-style-span" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-wrap: break-word; font-family: Simsun; line-height: normal; font-size: medium; "><font class="Apple-style-span" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-wrap: break-word; " color="#000080">s2 s1</font></span><span class="Apple-style-span" style="color: rgb(255, 165, 0); ">&nbsp;</span><span class="Apple-style-span" style="color: rgb(0, 0, 128); ">&nbsp;</span></span><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; "> s1 TMP &nbsp; ) </span><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;)</span><br><br><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(initget "H S")</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(setq key (getkword "[横向对齐(H)/竖向对齐(S)]:&nbsp;&nbsp;" ) )</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(cond </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (= key "H")&nbsp;&nbsp;(hen)</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (= key "S")&nbsp;&nbsp;(shu)</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;)</span><br><br><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp;&nbsp;(defun hen()</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(setq n 0)&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(repeat (length s1)&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq e1 (car (nth n s1))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;p1 (cadr (nth n s1))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(if (setq e2 (car (nth n s2)))&nbsp; &nbsp;&nbsp; &nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(progn&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq p2 (cadr (nth n s2)))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq p3 (list (car p2) (cadr p1) (caddr p2)))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(command "move" e2 "" p2 p3)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;) )&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq n (1+ n))&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp; &nbsp; </span><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp;&nbsp;)</span><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp;&nbsp;(defun shu()</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(setq n 0)&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(repeat (length s1)&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq e1 (car (nth n s1))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;p1 (cadr (nth n s1))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(if (setq e2 (car (nth n s2)))&nbsp; &nbsp;&nbsp; &nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(progn&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq p2 (cadr (nth n s2)))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(setq p3 (list (cadr p2) (car p1) (caddr p2)))&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(command "move" e2 "" p2 p3)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;) )&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(setq n (1+ n))&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp; &nbsp; </span><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp;&nbsp;)</span><br><br><br><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(setvar 'osmode osmode)&nbsp; &nbsp; </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(setvar 'cmdecho cmdecho) </span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">&nbsp; &nbsp;&nbsp; &nbsp;(princ)&nbsp;&nbsp;</span><br><span class="Apple-style-span" style="color: rgb(0, 0, 128); background-color: orange; ">)</span>

lidaxiu 发表于 2012-5-24 21:17:00

恩不错,可是没运行成功呢,提示no function definition: HEN

lz123456 发表于 2012-5-25 10:03:21

crazylsp
运行你修改的那后,无反应。那对齐没效果。cad2010 64

soly2006 发表于 2012-5-25 10:41:07

看看情况,拿分走人

dwg001 发表于 2012-5-26 22:45:29

学习G版的招数

梁智泓 发表于 2012-6-10 00:31:22

G版太强大了

ledisonsen 发表于 2012-6-19 14:34:42

看起来这个程序非常不错

yiming61 发表于 2012-6-19 15:14:55

批量对齐不错不错

ptime 发表于 2012-6-19 15:21:05

谢谢分享程序。
页: 3 4 5 6 7 8 9 10 11 12 [13] 14 15 16 17 18 19 20 21 22
查看完整版本: 能不能实现图元批量对齐,请大师们指教了