也许这会为你的目标指明方向:
- (defun c:square ( / pt2 pt2 ang ) ; Define function and localise variables
- (if ; If the following
- (and ; Both the statements must return T
- (setq pt1 (getpoint "\nSpecify First Point: ")) ; Prompt for first point
- (setq pt2 (getpoint "\nSpecify Opposite Corner: " pt1)) ; Prompt for second point
- )
- (progn
- (setq ang (- (angle pt1 pt2) (/ pi 4.))) ; get angle (in rads) and subtract 45 degrees
-
- (command "_.rectangle" "_non" pt1 "_R" (* 180. (/ ang pi)) "_non" pt2) ; Invoke Rectangle command
- )
- )
- (princ) ; Exit Quietly
- )
PS>这是一个很好的变量局部化方法,大多数人都忽略了这一点
要扩展,您必须注意OSnap,还可能考虑将CMDECHO切换到0,然后重置。但我们会一步一步来。 |