TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Ben Clark on March 16, 2017, 10:08:36 AM

Title: Function to convert selection set to vla selection set?
Post by: Ben Clark on March 16, 2017, 10:08:36 AM
Does anyone have a slick function that accepts a standard selection set (created using ssget) and converts it to a vla selection set?
Title: Re: Function to convert selection set to vla selection set?
Post by: Marco Jacinto on March 16, 2017, 11:15:37 AM
http://www.lee-mac.com/selectionsettolist.html
Title: Re: Function to convert selection set to vla selection set?
Post by: Grrr1337 on March 16, 2017, 12:36:58 PM
I've had similar idea before, but left it unfinished. So you could try this:

Code - Auto/Visual Lisp: [Select]
  1. ; SS - Pickset
  2. ; SSnm - name for the selection set to be stored in the SS collection
  3. (defun VanillaSS->VlaSS ( SS SSnm / i L SScoll SfArrayObjs vSS )
  4.   (cond
  5.     ( (not (eq 'PICKSET (type SS))) nil)
  6.     ( (not (and (eq 'STR (type SSnm)) (snvalid SSnm))) nil)
  7.     (T
  8.       (repeat (setq i (sslength SS))
  9.         (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  10.       )
  11.       (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list SScoll SSnm))))
  12.         (vla-Delete (vla-Item SScoll SSnm))
  13.       )
  14.       (setq vSS (vla-Add SScoll SSnm))
  15.       (setq SfArrayObjs (vlax-make-safearray vlax-vbObject (cons 0 (1- (length L)))))
  16.       (setq i -1)
  17.       (foreach o L (vlax-safearray-put-element SfArrayObjs (setq i (1+ i)) o) )
  18.       (vla-AddItems vSS SfArrayObjs)
  19.       vSS
  20.     )
  21.   ); cond
  22. ); defun VanillaSS->VlaSS
  23.  
Title: Re: Function to convert selection set to vla selection set?
Post by: ronjonp on March 16, 2017, 01:36:16 PM
Quick one to vla list .. what are you doing with a vla ss that you can't accomplish with a list of vla objects?
Code - Auto/Visual Lisp: [Select]
  1. (defun ss2vlalst (ss)
  2.   (if (= (type ss) 'pickset)
  3.     (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  4.   )
  5. )
  6. ;; (ss2vlalst (ssget))

Title: Re: Function to convert selection set to vla selection set?
Post by: Grrr1337 on March 16, 2017, 01:44:10 PM
what are you doing with a vla ss that you can't accomplish with a list of vla objects?

Saving it as a named SS, that could be gripped later (I think).
But I like tasks, even if they have purely academical purpose.
Title: Re: Function to convert selection set to vla selection set?
Post by: ronjonp on March 16, 2017, 01:48:51 PM
what are you doing with a vla ss that you can't accomplish with a list of vla objects?

Saving it as a named SS, that could be gripped later (I think).
But I like tasks, even if they have purely academical purpose.
I like tasks too, but also like to know why I'm trying to solve that task when other avenues are simpler :).