TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Colby on November 08, 2019, 12:01:19 PM
-
I wanted to do something like the following:
(defun SelectionSet->VLA-Object (ssEnt / obj)
(if (/= ssEnt nil)
(setq obj (vlax-ename->vla-object (ssname ssEnt 0)))
nil
)
)
(defun C:SSS ()
(setq ssents (ssget))
(setq temp (mapcar 'SelectionSet->vla-object ssents))
)
If I review ssents in VLIDE, it appears very list-esq, but does not seem to function like one. Is something like this possible?
[edit] I know I can loop through it with repeat, but I'd like to minimize the amount of typing I need to do in the future.
-
Read this: http://www.lee-mac.com/selectionsettolist.html
You have to convert the selset to a list .. many examples there.
Welcome to TheSwamp. :)
Here is an example using mapcar albeit slower than many other methods:
-
Read this: http://www.lee-mac.com/selectionsettolist.html
You have to convert the selset to a list .. many examples there.
Welcome to TheSwamp. :)
Here is an example using mapcar albeit slower than many other methods:
Thanks ronjonp!
It looks like using mapcar on the function selectionset->vla-object and passing each selection set item just isn't possible.
Thank you for your help.
-
In short: mapcar operates on lists; a selection set isn't a list.
If you specifically wish to use mapcar, you will need to first construct a list of entities from a given selection set either by iterating over the set or using ssnamex; however, rather than iterating over the selection set to construct a list, and then iterating over the list (using mapcar or other list iterators) to operate on each entity, you might as well operate on the entities whilst iterating over the set - I describe various methods to accomplish this in my tutorial on Selection Set Processing (http://lee-mac.com/selsetprocessing.html).
-
Another version:
(defun ALE_SelSet_ToObjList (SelSet / Countr ObjLst)
(if SelSet
(repeat (setq Countr (sslength SelSet))
(setq ObjLst (cons (vlax-ename->vla-object (ssname SelSet (setq Countr (1- Countr)))) ObjLst))
)
)
)