Code Red > AutoLISP (Vanilla / Visual)

Can a PICKSET be treated as a list for use with mapcar?

(1/1)

Colby:
I wanted to do something like the following:


--- Code: ---(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))
   )
--- End code ---

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.

ronjonp:
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:


--- Code - Auto/Visual Lisp: ---(defun selectionset->vla-object_>list (s)  (if s    (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))  ))

Colby:

--- Quote from: ronjonp on November 08, 2019, 12:23:08 PM ---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:


--- Code - Auto/Visual Lisp: ---(defun selectionset->vla-object_>list (s)  (if s    (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))  ))
--- End quote ---

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.

Lee Mac:
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.

Marc'Antonio Alessi:
Another version:

--- Code: ---(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))
    )
  )
)
--- End code ---

Navigation

[0] Message Index

Go to full version