TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Red Nova on December 07, 2016, 11:20:08 PM
-
Hi,
For sure I am missing something...
I convert Selection Set into a list of VLA Objects using following function from Lee Mac.
But how do I convert a list of VLA Objects back to a Selection Set?
(defun LM:ss->vla ( ss / i l )
(if ss
(repeat (setq i (sslength ss))
(setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
)
)
)
-
Coded blind on an iPad (surprisingly horrible experience).
(defun _Objects->SS ( objects )
( (lambda ( ss )
(foreach e (mapcar 'vlax-vla-object->ename objects)
(ssadd e ss)
)
ss
)
(ssadd)
)
)
Should work, apologies if it throws ones and zeros at you.
PS: If you don't like the order in the resulting selection set reverse the list of objects.
-
PS: Likely doesn't need the trailing ss as (ssadd e ss) should return the selection set. Can't test here so went the safe explicit route.
-
Simpler and probably faster:
(defun Conv_ObjectList_To_Pickset (objLst / ss)
(setq ss (ssadd))
(foreach obj objLst (ssadd (vlax-vla-object->ename obj) ss))
)
Or if you want the function to return nil instead of an empty selection set:
(defun Conv_ObjectList_To_Pickset (objLst / ss) ; Returns nil if objLst is empty.
(if objLst
(progn
(setq ss (ssadd))
(foreach obj objLst (ssadd (vlax-vla-object->ename obj) ss))
)
)
)
-
Thank you roy_043 and MP. What I needed :).
-
Heres to convert into a selection set object:
(defun VlaObjs->SS ( LstObjs / SScoll SS SfArrayObjs i )
(setq SScoll (vla-get-SelectionSets (vla-get-ActiveDocument (vlax-get-acad-object))))
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list SScoll "NewSS"))))
(vla-Delete (vla-Item SScoll "NewSS"))
)
(setq SS (vla-Add SSColl "NewSS"))
(setq SfArrayObjs (vlax-make-safearray vlax-vbObject (cons 0 (1- (length LstObjs)))))
(setq i -1)
(foreach o LstObjs
(vlax-safearray-put-element SfArrayObjs (setq i (1+ i)) o)
)
(vla-AddItems SS SfArrayObjs)
SS
)
Seems useless, but who knows.
-
Another, just to offer an alternative to those posted:
-
Another, just to offer an alternative to those posted:
Creative! :-)