@dbhunia wrote:
....
....
(setq ss (ssget ":L" '((0 . "LWPOLYLINE")(70 . 1))))
....
I would point out that you must not have tried that including any closed Polylines with linetype generation enabled, because their 70-code entry will be (70 . 129) and will not be "seen" in that selection.
But also, it can be done without building a whole list of sub-lists pairing entity names with lengths, and then sorting that by the lengths. It can just step through the selection, and if the current one's length is the shortest length found so far, make that the one to be selected/highlighted/gripped. Lightly tested:
(vl-load-com); if needed
(defun C:SCPL (/ ss len n pl pllen shortest); = Shortest Closed PolyLine
(if (setq ss "_:L" (ssget '((0 . "LWPOLYLINE") (-4 . "&") (70 . 1))))
;; finds closed Polylines with or without linetype generation enabled
(progn
(setq len 1e10); initial reference, assuming none billions of units long
(repeat (setq n (sslength ss))
(setq
pl (ssname ss (setq n (1- n))); the current Polyline
pllen (vlax-curve-getDistAtParam pl (vlax-curve-getEndParam pl)); its length
len (min pllen len); whichever is shorter
); setq
(if (= pllen len) (setq shortest (ssadd pl))); shortest? make this the one
); repeat
(sssetfirst nil shortest); select/highlight/grip result
); progn
); if
(princ)
); defun
[Depending on what you want to do about the shortest one, you might omit the restriction to only those on unlocked Layers -- the "_:L" in the (ssget) function. If you only want to know which it is, or how long it is, or what Layer it's on, or something, but don't want to do anything to it, it wouldn't matter whether its Layer is locked.]
Kent Cooper, AIA