こちらからサブルーチンをいくつかお借りしました。
https://www.lee-mac.com/
コマンド名はcorvalです。
2次元限定で、対象は、線・2Dポリライン・円・円弧・点、範囲内の端点・頂点・中心・交点の座標を書き込みます。
-------------------------------------------------------
(defun c:corval (/ ss inf pt1 pt2 pt_lb pt_rt pt cnt pt_lst pt_w pt_l l_ang l_leng i ent pent pt_ck1 pt_ck2 gap)
(vl-load-com)
(setq pt1 (getpoint "\n窓選択の1点目を指定:"))
(setq pt2 (getcorner pt1 "\n窓選択の2点目を指定:"))
;線、ポリライン、円、円弧、点のみ対象
(setq ss (ssget "C" pt1 pt2 '((0 . "*LINE,CIRCLE,ARC,POINT"))))
;選択範囲の左下と右上座標を作成
(setq pt1 (trans pt1 1 0))
(setq pt2 (trans pt2 1 0))
(setq pt_lb (list (min (car pt1)(car pt2))(min (cadr pt1)(cadr pt2))))
(setq pt_rt (list (max (car pt1)(car pt2))(max (cadr pt1)(cadr pt2))))
;交点リスト作成
(setq pt_lst (LM:intersectionsinset ss))
(setq i 0)
(repeat (sslength ss)
(setq ent (entget (ssname ss i)))
(setq pt (cdr (assoc 10 ent)))
(setq pt (list (car pt) (cadr pt)))
(if (= nil (member pt pt_lst))
(setq pt_lst (cons pt pt_lst))
)
;線の場合、終点取得
(if (wcmatch (cdr (assoc 0 ent)) "LINE")
(progn
(setq pt (cdr (assoc 11 ent)))
(setq pt (list (car pt) (cadr pt)))
(if (= nil (member pt pt_lst))
(setq pt_lst (cons pt pt_lst))
)
)
)
;ポリラインの各頂点(始点除く)
(if (wcmatch (cdr (assoc 0 ent)) "LWPOLYLINE")
(progn
(setq cnt (cdr (assoc 90 ent))) ;頂点数カウント
(setq pent ent)
(repeat (- cnt 1)
(setq pent (cdr (member (assoc 10 pent) pent)))
(setq pt (cdr (assoc 10 pent)))
(if (= nil (member pt pt_lst))
(setq pt_lst (cons pt pt_lst))
)
)
)
)
;円弧の始点・終点
(if (wcmatch (cdr (assoc 0 ent)) "ARC")
(progn
(setq pt (vlax-curve-getstartpoint (ssname ss i)))
(setq pt (list (car pt) (cadr pt)))
(if (= nil (member pt pt_lst))
(setq pt_lst (cons pt pt_lst))
)
(setq pt (vlax-curve-getendpoint (ssname ss i)))
(setq pt (list (car pt) (cadr pt)))
(if (= nil (member pt pt_lst))
(setq pt_lst (cons pt pt_lst))
)
)
)
(setq i (+ 1 i))
)
;座標でソート
(setq pt_lst
(vl-sort pt_lst
'(lambda (a b)
(cond
((< (car a) (car b)))
((= (car a) (car b)) (< (cadr a) (cadr b)))
)
)
)
)
;重複座標チェック
(setq gap (expt 0.1 (+ 1 (getvar "LUPREC"))))
(repeat (length pt_lst)
(setq pt_ck1 (car pt_lst))
(setq pt_ck2 (cadr pt_lst))
(if (equal pt_ck1 pt_ck2 gap)
(setq pt_lst (cdr pt_lst))
(setq pt_lst (append (cdr pt_lst) (list pt_ck1)))
)
)
;引出線の制御点:方向は60度、長さは250に設定
(setq l_ang (* pi (/ 60 180.0)))
(setq l_leng 250)
(foreach pt_w pt_lst
(if (and (>= (car pt_w) (car pt_lb))(>= (cadr pt_w) (cadr pt_lb))
(<= (car pt_w) (car pt_rt))(<= (cadr pt_w) (cadr pt_rt)))
(progn
(setq pt_l (polar pt_W l_ang l_leng))
(command "_ucs" "w" "_leader" pt_w pt_l "A" (strcat "X=" (rtos (car pt_w))) (strcat "Y=" (rtos (cadr pt_w))) "" "_ucs" "p")
)
)
)
(redraw)
(princ)
)
;; Intersections - Lee Mac
;; Returns a list of all points of intersection between two objects
;; for the given intersection mode.
;; ob1,ob2 - [vla] VLA-Objects
;; mod - [int] acextendoption enum of intersectwith method
(defun LM:intersections ( ob1 ob2 mod / lst rtn )
(if (and (vlax-method-applicable-p ob1 'intersectwith)
(vlax-method-applicable-p ob2 'intersectwith)
(setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
)
(repeat (/ (length lst) 3)
;(setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
(setq rtn (cons (list (car lst) (cadr lst)) rtn)
lst (cdddr lst)
)
)
)
(reverse rtn)
)
;; Intersections in Set - Lee Mac
;; Returns a list of all points of intersection between all objects in a supplied selection set.
;; sel - [sel] Selection Set
(defun LM:intersectionsinset ( sel / id1 id2 ob1 ob2 rtn )
(repeat (setq id1 (sslength sel))
(setq ob1 (vlax-ename->vla-object (ssname sel (setq id1 (1- id1)))))
(repeat (setq id2 id1)
(setq ob2 (vlax-ename->vla-object (ssname sel (setq id2 (1- id2))))
rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn)
)
)
)
(apply 'append (reverse rtn))
)
;; Unique - Lee Mac
;; Returns a list with duplicate elements removed.
(defun LM:Unique ( l )
(if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l)))))
)
-------------------------------------------------------
引出線の設定は、
下記のところの、60と250を書き換えてください。
(setq l_ang (* pi (/ 60 180.0)))
(setq l_leng 250)