benhubel 发表于 2022-7-5 18:16:12

LISP用于快速旋转/对齐X?

说到LISP,我是一个绝对的初学者,我正在尝试编写一个例程。在尝试了几个教程之后,我决定来这里。
 
我正在尝试编写一个程序,当用户单击一条直线或曲线时,该程序将选择与X轴对齐。我还想包括一个与Y轴对齐的特征,但这可能会在稍后出现。
 
有一个来自李·麦克的快速镜像Lisp程序(http://www.lee-mac.com/quickmirror.html)它执行大部分所需步骤。我试图破译它,但我不知道从哪里开始裁剪它以满足我的需要。
 
如果这样一个程序已经存在,我很乐意参与,因为它会节省我大量的时间。使用“对齐”命令需要太多的单击(并且每次单击需要太多的精度)。

Lee Mac 发表于 2022-7-5 18:29:34

欢迎来到CADTutor
 
你能详细解释一下“将选定内容与X轴对齐”是什么意思吗?
 
例如,是否应围绕其边界框的中心旋转选择,以使选定对象上的点与x轴对齐?例如。:
 

Grrr 发表于 2022-7-5 18:41:00

也许你会在这个帖子中发现一些有用的东西:http://www.cadtutor.net/forum/showthread.php?85946-对齐对象并单击2次

benhubel 发表于 2022-7-5 18:56:03

李-谢谢!
我实际上已经把那部分想透了,但忘了提。由于我缺乏经验,我一直保持简单。我想把目标线段的中心点作为旋转中心。一旦我弄清楚事物是如何工作的,理想的做法是围绕质心旋转,然后将其移动到图纸上最近的空白处。
 
Grrr-看起来它足够接近我想要的东西,并且可能包含足够的代码,让我未经训练的头脑用quick mirror将其拼凑在一起以制作一些东西。
 
我希望今晚下班后能提供更多信息。我欢迎任何人编写代码,但如果你这样做了,请在代码中留下许多注释,以便我可以学习如何复制这个过程。我主要是想教自己精通LISP编码。
谢谢

Lee Mac 发表于 2022-7-5 19:02:14

以下是一种非常简单(且评论颇丰)的入门方法,仅适用于与行对齐:
;; Define function, declare local variables
(defun c:alignx ( / ent enx pt1 pt2 sel )
   ;; If the user makes a selection of objects (on unlocked layers)
   (if (setq sel (ssget "_:L"))
       ;; If the user selects a single object
       (if (setq ent (car (entsel "\nSelect line to align with x-axis: ")))
         ;; If the selected object is a LINE
         (if (= "LINE" (cdr (assoc 0 (setq enx (entget ent)))))
               ;; Then evaluate the following expressions
               (progn
                   ;; Retrieve the WCS start & end points and translate them to UCS
                   (setq pt1 (trans (cdr (assoc 10 enx)) 0 1)
                         pt2 (trans (cdr (assoc 11 enx)) 0 1)
                   ) ;; end setq
                   ;; Invoke the Rotate command
                   (command "_.rotate"
                     ;; Pass the selection of objects
                     sel ""
                     ;; Specify the line midpoint as the rotation base point
                     "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2)
                     ;; Rotate the reference line to zero
                     "_R" "_non" pt1 "_non" pt2 0.0
                   ) ;; end command
               ) ;; end progn
               ;; Else the selected alignment object was not a line
               (princ "\nThe selected object is not a line.")
         ) ;; end if
         ;; Else no alignment object was selected
         (princ "\nNo alignment object selected.")
       ) ;; end if
       ;; Else no objects were selected
       (princ "\nNo objects selected.")
   ) ;; end if
   ;; Supress the value returned by the last evaluated expression
   (princ)
) ;; end defun

benhubel 发表于 2022-7-5 19:12:27

含糖的我来玩玩这个。非常感谢。

Lee Mac 发表于 2022-7-5 19:23:54

不客气-我希望这会有所帮助!
页: [1]
查看完整版本: LISP用于快速旋转/对齐X?