以下是一种非常简单(且评论颇丰)的入门方法,仅适用于与行对齐:
- ;; 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
|