{"id":1293,"date":"2012-09-07T01:39:46","date_gmt":"2012-09-06T17:39:46","guid":{"rendered":"https:\/\/www.highflybird.com\/blog\/?p=128"},"modified":"2012-09-07T01:39:46","modified_gmt":"2012-09-06T17:39:46","slug":"%e9%ab%98%e4%bb%bfalign%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.highflybird.com\/blog\/?p=1293","title":{"rendered":"\u9ad8\u4effALIGN\u547d\u4ee4"},"content":{"rendered":"<p>CAD\u4e2d\u5e73\u9f50\u7269\u4f53\u7684\u5b9e\u73b0\u662f\u901a\u8fc7align\u547d\u4ee4\u6765\u5b9e\u73b0\u7684\u3002<br \/>\n\u4f46\u5728CAD\u7f16\u7a0b\u4e2d\u6709\u65f6\u5019\u9700\u8981\u5bf9\u8fd9\u4e2a\u547d\u4ee4\u81ea\u5b9a\u4e49\uff0c\u800c\u4e14\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u9002\u5408\u7528\u547d\u4ee4\u5f62\u5f0f\u3002<br \/>\n\u6240\u4ee5\u6211\u7f16\u5199\u4e86\u4e00\u4e2alisp\u7a0b\u5e8f\uff0c\u7528\u6237\u4e5f\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u7a0b\u5e8f\u5b9a\u4e49\u66f4\u9ad8\u7ea7\u7684\u5e73\u9f50\u3002<br \/>\n\u4e0b\u9762\u662f\u5b9e\u73b0\u7684\u4ee3\u7801\u3002<br \/>\n<!--more--><br \/>\n[codesyntax lang=&#8221;lisp&#8221;];;;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;;;<br \/>\n;;; To simulate the command: &#8220;align&#8221;                          ;;<br \/>\n;;; Command:Align3d                                           ;;<br \/>\n;;; Use in some cases: command can&#8217;t be applied or you don&#8217;t  ;;<br \/>\n;;; want to use them; or improve the efficiency,etc.and here  ;;<br \/>\n;;; are some useful functions,e.g. &#8220;Mat:Get3PMatrix&#8221;;Or even  ;;<br \/>\n;;; you can customize &#8220;align&#8221; command.                        ;;<br \/>\n;;; Author: Highflybird, Date:2012-8-6.                       ;;<br \/>\n;;; All copyrights reserved.                                  ;;<br \/>\n;;;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;;;<br \/>\n(defun C:Align3d (\/ sel sP1 sP2 sP3 dP1 dP2 dP3 sclp scl<br \/>\n                    mat0 mat1 mat2 mat i ent obj app doc)<br \/>\n  ;;input<br \/>\n  (setq sel (ssget))<br \/>\n  (initget 9)<br \/>\n  (setq sP1 (getpoint &#8220;nSpecify first source point:&#8221;))<br \/>\n  (initget 9)<br \/>\n  (setq dP1 (getpoint &#8220;nSpecify first destination point:&#8221;))<br \/>\n  (initget 9)<br \/>\n  (setq sP2 (getpoint &#8220;nSpecify second source point:&#8221;))<br \/>\n  (initget 9)<br \/>\n  (setq dP2 (getpoint &#8220;nSpecify second destination point:&#8221;))<br \/>\n  (initget 8)<br \/>\n  (setq sP3 (getpoint &#8220;nSpecify third source point or &lt;continue&gt;:&#8221;))<br \/>\n  (initget 9)<br \/>\n  (if (null sP3)<br \/>\n    (setq sP3 (Mat:Rotate90 sP2 sP1)<br \/>\n          dP3 (Mat:Rotate90 dP2 dP1)<br \/>\n    )<br \/>\n    (setq dP3 (getpoint &#8220;nSpecify third destination point:&#8221;))<br \/>\n  )<br \/>\n  (foreach x &#8216;(sP1 sP2 sP3 dP1 dP2 dP3)<br \/>\n    (set x (trans (eval x) 1 0))<br \/>\n  )<br \/>\n  (initget &#8220;Yes No&#8221;)<br \/>\n  (setq sclp (getkword &#8220;nScale objects based on alignment points? [Yes\/No] &lt;N&gt;:&#8221;))<\/p>\n<p>  ;;Get the transformation matrix<br \/>\n  (setq mat1 (Mat:3PMatrix sP1 sP2 sP3 nil))<br \/>\n  (setq mat2 (Mat:3PMatrix dP1 dP2 dP3 T))<br \/>\n  (if (= &#8220;Yes&#8221; sclp)<br \/>\n    (setq scl (\/ (distance dP1 dP2) (distance sP2 sP1))<br \/>\n          mat0 (list (list scl 0 0 0)(list 0 scl 0 0) (list 0 0 scl 0) &#8216;(0 0 0 1))<br \/>\n          mat (Mat:mxm mat2 (Mat:mxm mat0 mat1))<br \/>\n    )<br \/>\n    (setq mat (Mat:mxm mat2 mat1))<br \/>\n  )<\/p>\n<p>  ;;Apply the transformation.<br \/>\n  (setq app (vlax-get-acad-object))<br \/>\n  (setq doc (vla-get-ActiveDocument app))<br \/>\n  (vla-StartUndoMark doc)<br \/>\n  (setq i 0)<br \/>\n  (if sel<br \/>\n    (repeat (sslength sel)<br \/>\n      (setq ent (ssname sel i))<br \/>\n      (setq obj (vlax-ename-&gt;vla-object ent))<br \/>\n      (vla-transformby obj (vlax-tmatrix mat))<br \/>\n      (setq i (1+ i))<br \/>\n    )<br \/>\n  )<br \/>\n  (vla-EndUndoMark doc)<br \/>\n  (vlax-release-object doc)<br \/>\n  (vlax-release-object app)<br \/>\n  (princ)<br \/>\n)<\/p>\n<p>;;;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;;;<br \/>\n;;; Mat:Rotate90 Rotate a point 90 degree by a basepoint      ;;<br \/>\n;;;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;;;<br \/>\n(defun Mat:Rotate90 (Pt BasePt \/ a)<br \/>\n  (setq a (+ (\/ pi 2) (angle BasePt Pt)))<br \/>\n  (polar BasePt a (distance pt basePt))<br \/>\n)<br \/>\n(prompt &#8220;Command is: Align3d&#8221;)<br \/>\n(princ)<br \/>\n[\/codesyntax]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CAD\u4e2d\u5e73\u9f50\u7269\u4f53\u7684\u5b9e\u73b0\u662f\u901a\u8fc7align\u547d\u4ee4\u6765\u5b9e\u73b0\u7684\u3002 \u4f46\u5728CAD\u7f16\u7a0b\u4e2d\u6709\u65f6\u5019\u9700\u8981\u5bf9\u8fd9\u4e2a\u547d\u4ee4\u81ea\u5b9a\u4e49\uff0c\u800c\u4e14\u5728\u67d0\u4e9b\u60c5<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/www.highflybird.com\/blog\/?p=1293\" class=\"themebutton2\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[10],"class_list":["post-1293","post","type-post","status-publish","format-standard","hentry","category-programming","tag-align"],"_links":{"self":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1293"}],"version-history":[{"count":0,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1293\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}