2016-10-01 12 views
0

私は初心者です/ autocadのlispを書く。
以下はインターネット上で見つけたコードです。初心者として、私はそれを変更したいのですが、(1行の)line1とline2を選択する代わりに、複数の行を選択したい(2行を選択する)。何か案が?ユーザー入力:2行を選択

;------------------------------------------------------------------------ 
;- 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) 
) 

答えて

0

entselは、1つのエンティティのみを選択することができます。複数の選択が必要な場合は、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は非常に便利です。エンティティを選択するようにユーザーに依頼することもできます。また、ユーザーの選択を制限することもできます。たとえば、行のみ、またはブロックのみを選択できます。レイヤー、色などの定義済みの基準でエンティティを選択することもできますが、ユーザーの操作は必要ありません。

0

前の返信には、 'ssget文の後に(list)内に設定されたプロパティフィルタは含まれていません。 LINEエンティティ以外のすべてをフィルタリングする必要がある場合は、フィルタセットを含める必要があります。

関連する問題