Author Topic: Function to convert selection set to vla selection set?  (Read 2382 times)

0 Members and 1 Guest are viewing this topic.

Ben Clark

  • Newt
  • Posts: 94
Function to convert selection set to vla selection set?
« 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?


Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Function to convert selection set to vla selection set?
« Reply #2 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.  
(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

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Function to convert selection set to vla selection set?
« Reply #3 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))


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Function to convert selection set to vla selection set?
« Reply #4 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.
(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

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Function to convert selection set to vla selection set?
« Reply #5 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 :).

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC