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

0 Members and 1 Guest are viewing this topic.

barnjart42

  • Mosquito
  • Posts: 3
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

  • Bull Frog
  • Posts: 236
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.  

ronjonp

  • Needs a day job
  • Posts: 6122
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 10 x64 - AutoCAD 2017

Custom Build PC

Grrr1337

  • Bull Frog
  • Posts: 236
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.

ronjonp

  • Needs a day job
  • Posts: 6122
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 10 x64 - AutoCAD 2017

Custom Build PC