;;; Make Polyline Selection (draw pline and Select Objects Within/Crossing it)
;;; Created by Igal Averbuh 2017 (inspired by some ideas from http://www.cadtutor.net/forum/)
;;; Special thanks to Alan J. Thompson

(defun c:SWC (/ _pac add ss i e temp it o a b pts tempC i3 ec)
;; Select Objects Within/Crossing Curve
;; Alan J. Thompson, 03.31.11
;; Slightly modified by Igal Averbuh 2017 (added option for splines)
(vl-load-com)

(defun _pac (e / l v d lst)
(setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
(while (< (setq d (+ d v)) l)
(setq lst (cons (vlax-curve-getPointAtDist e d) lst))
)
)

(initget 0 "Crossing Within")
(setq *SWC:Opt*
(cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] : "
)
)
)
(*SWC:Opt*)
)
)

(princ "\nSelect closed curves to select object(s) within: ")
(if (setq add (ssadd)
ss (ssget "L"

)
)
(progn (repeat (setq i (sslength ss))
(if (setq temp (ssget "_WP" (_pac (setq e (ssname ss (setq i (1- i)))))))
(repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
)

(if (eq *SWC:Opt* "Crossing")
(progn (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'a 'b)
(setq pts (mapcar 'vlax-safearray->list (list a b)))
(if (setq tempC (ssget "_C"
(list (caar pts) (cadar pts) 0.)
(list (caadr pts) (cadadr pts) 0.)
)
)
(repeat (setq i3 (sslength tempC))
(if (vlax-invoke
o
'Intersectwith
(vlax-ename->vla-object (setq ec (ssname tempC (setq i3 (1- i3)))))
acExtendNone
)
(ssadd ec add)
)
)
)
)
)
)
(sssetfirst nil add)
(ssget "_I")
)
)
(princ)
)

(defun C:PAS ()
(setvar "osmode" 16384)

(command "_.pline")
(while (> (getvar "CmdActive") 0)
(command pause)
)
(c:swc)
(princ)
)

Advertisements