나는 autocad lisp를 사용/작성하는 초보자입니다.
다음은 인터넷에서 찾은 코드입니다. 초보자로서 나는 그것을 수정하기를 원하고 (단선) line1과 line2를 선택하는 대신 여러 줄의 선택 (두 줄 선택)을하고 싶다. 어떤 생각?사용자 입력 : 두 줄 선택
;------------------------------------------------------------------------
;- Command: midpts_line()
;-
;- Draws a line between the midpoints of two lines.
;-
;- Copyright 2008 Jeff Winship. All rights Reserved.
;----------------------------------------------------------------5/3/2008
(defun c:midpts_line()
;-- Select the lines
(setq line1 (car (entsel "\nSelect the first line: ")))
(setq line2 (car (entsel "\nSelect the second line: ")))
;-- Get the endpoints of the first selected line
(setq pt1 (cdr (assoc 10 (entget line1))))
(setq pt2 (cdr (assoc 11 (entget line1))))
;-- Get the endpoints of the second selected line
(setq pt3 (cdr (assoc 10 (entget line2))))
(setq pt4 (cdr (assoc 11 (entget line2))))
;-- Find the midpoints of the lines
(setq mid1 (midpt pt1 pt2))
(setq mid2 (midpt pt3 pt4))
;-- Draw the line
(command "line" mid1 mid2 "")
)
;------------------------------------------------------------------------
;- Function: midpt (p1 p2)
;- Arguments: p1 is the starting point of the line
;- p2 is the ending point of the line
;-
;- Returns the midpoint of a line given two points.
;-
;- Copyright 2008 Jeff Winship. All rights Reserved.
;----------------------------------------------------------------5/3/2008
(defun midpt (p1 p2/Xavg Yavg Zavg)
;-Calculate the X, Y and Z averages
(setq Xavg (/(+ (car p1) (car p2))2.0))
(setq Yavg (/(+ (cadr p1) (cadr p2))2.0))
(setq Zavg (/(+ (caddr p1) (caddr p2))2.0))
;-Return the midpoint as a list
(list Xavg Yavg Zavg)
)