Author Topic: Can a PICKSET be treated as a list for use with mapcar?  (Read 2799 times)

0 Members and 1 Guest are viewing this topic.

Colby

  • Guest
Can a PICKSET be treated as a list for use with mapcar?
« on: November 08, 2019, 12:01:19 PM »
I wanted to do something like the following:

Code: [Select]
(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.
« Last Edit: November 08, 2019, 12:22:14 PM by Colby »

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Can a PICKSET be treated as a list?
« Reply #1 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: [Select]
  1. (defun selectionset->vla-object_>list (s)
  2.   (if s
  3.     (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  4.   )
  5. )
« Last Edit: November 08, 2019, 12:26:25 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Colby

  • Guest
Re: Can a PICKSET be treated as a list?
« Reply #2 on: November 08, 2019, 12:33:20 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: [Select]
  1. (defun selectionset->vla-object_>list (s)
  2.   (if s
  3.     (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  4.   )
  5. )

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

  • Seagull
  • Posts: 12912
  • London, England
Re: Can a PICKSET be treated as a list for use with mapcar?
« Reply #3 on: November 08, 2019, 01:55:11 PM »
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

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Can a PICKSET be treated as a list for use with mapcar?
« Reply #4 on: November 09, 2019, 03:57:17 AM »
Another version:
Code: [Select]
(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))
    )
  )
)