Author Topic: Convert list of VLA Objects to a Selection Set  (Read 2832 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
Convert list of VLA Objects to a Selection Set
« 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))
        )
    )
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Convert list of VLA Objects to a Selection Set
« Reply #1 on: December 07, 2016, 11:33:36 PM »
Coded blind on an iPad (surprisingly horrible experience).

Code: [Select]
(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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Convert list of VLA Objects to a Selection Set
« Reply #2 on: December 07, 2016, 11:46:16 PM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Convert list of VLA Objects to a Selection Set
« Reply #3 on: December 08, 2016, 05:37:45 AM »
Simpler and probably faster:
Code: [Select]
(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:
Code: [Select]
(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))
    )
  )
)

Red Nova

  • Newt
  • Posts: 69
Re: Convert list of VLA Objects to a Selection Set
« Reply #4 on: December 08, 2016, 07:42:20 AM »
Thank you roy_043 and MP. What I needed :).

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Convert list of VLA Objects to a Selection Set
« Reply #5 on: December 08, 2016, 07:53:28 AM »
Heres to convert into a selection set object:
Code: [Select]
(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.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Convert list of VLA Objects to a Selection Set
« Reply #6 on: December 11, 2016, 05:24:25 PM »
Another, just to offer an alternative to those posted:
Code - Auto/Visual Lisp: [Select]
  1. (defun vla->ss ( lst )
  2.     (apply 'command (append '("_.select") (mapcar 'vlax-vla-object->ename lst) '("")))
  3.     (ssget "_P")
  4. )

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Convert list of VLA Objects to a Selection Set
« Reply #7 on: December 12, 2016, 05:03:59 AM »
Another, just to offer an alternative to those posted:
Code - Auto/Visual Lisp: [Select]
  1. (defun vla->ss ( lst )
  2.     (apply 'command (append '("_.select") (mapcar 'vlax-vla-object->ename lst) '("")))
  3.     (ssget "_P")
  4. )
Creative!  :-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg