0

我是使用/编写 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)
)
4

2 回答 2

0

上一个回复不包括在 'ssget 语句之后的 (list ) 中设置的属性过滤器。如果您需要过滤掉除 LINE 实体之外的所有内容,则需要包含一个过滤器集。

于 2017-04-20T02:41:50.207 回答
0

entsel只允许选择一个实体。如果你想要多选,你应该使用ssget

示例代码:

(setq sset(vl-catch-all-apply 'ssget (list )))
(if (not(vl-catch-all-error-p sset))
  (progn
    (setq i 0)
    (repeat (sslength sset)
        (setq item (ssname sset i))
        (print (entget item) )
        (setq i (1+ i))
    );repeat
  ) ; progn
) ;if

SSget 非常有用。您可以要求用户选择实体,您还可以限制用户的选择,例如他将能够仅选择行或仅选择块。您还可以通过定义的标准(如图层、颜色等)选择实体,而无需任何用户操作。

于 2016-10-04T06:11:13.243 回答