Author Topic: Selection sets in Visual Lisp  (Read 4418 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
Selection sets in Visual Lisp
« on: September 17, 2018, 09:04:32 AM »
Hi guys.

Not so good with Visual lisp, so need a little help here :)
How to I convert from something like this
Code - Auto/Visual Lisp: [Select]
  1. '(#<VLA-OBJECT IAcadBlockReference 000002ca284f79f8> #<VLA-OBJECT IAcadBlockReference 000002ca284f9668> #<VLA-OBJECT IAcadBlockReference 000002ca284f8488>)
this
Code - Auto/Visual Lisp: [Select]
  1. '#<VLA-OBJECT IAcadSelectionSet 000002ca2af35f78>

and also how to convert vice versa.
Also please tell me how to call each version properly.
Do I understand it properly that '#<VLA-OBJECT IAcadSelectionSet 000002ca2af35f78> is the actual selection set in Visual lisp and the other list is the list of entities that it contains?

Thank you

kpblc

  • Bull Frog
  • Posts: 396
Re: Selection sets in Visual Lisp
« Reply #1 on: September 17, 2018, 09:11:18 AM »
Try to create named selection set and then add objects to it. It seems like this:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun test (obj-lst / adoc name selset)
  3.         name "TempSelSet"
  4.         ) ;_ end of setq
  5.   (vl-catch-all-apply (function (lambda () (vla-delete (vla-item (vla-get-selectionsets adoc) name))))
  6.                       ) ;_ end of vl-catch-all-apply
  7.   (setq selset (vla-add (vla-get-selectionsets adoc) name))
  8.   (vla-additems selset
  9.                 (vlax-make-variant
  10.                   (vlax-safearray-fill (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj-lst)))) obj-lst)
  11.                   ) ;_ end of vlax-make-variant
  12.                 ) ;_ end of vla-additems
  13.   ) ;_ end of defun
  14.  
Sorry for my English.

Red Nova

  • Newt
  • Posts: 69
Re: Selection sets in Visual Lisp
« Reply #2 on: September 17, 2018, 10:39:16 AM »
kpblc,

Thanks. Couldn't make it work yet.
What should obj-lst be in the input?

P.S. привет маестро :)

kpblc

  • Bull Frog
  • Posts: 396
Re: Selection sets in Visual Lisp
« Reply #3 on: September 17, 2018, 10:40:51 AM »
I mean that obj-lst is list of objects you want to add to selection set.
What is the reason to work with selection set? Maybe there is another way exist to solve your problem ;)
--
ЗЫ - Привет! :)
Sorry for my English.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Selection sets in Visual Lisp
« Reply #4 on: September 17, 2018, 11:14:20 AM »
And the reverse process - from SS vla-object to a list of vla-objects:

Code - Auto/Visual Lisp: [Select]
  1. (defun oSS->oL ( oSS / oL )
  2.   (and
  3.     (eq 'VLA-OBJECT (type oSS))
  4.     (vlax-property-available-p oSS 'Name)
  5.     (vlax-for o oSS (setq oL (cons o oL)))
  6.   ); and
  7.   oL
  8. ); defun oSS->oL
(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

Red Nova

  • Newt
  • Posts: 69
Re: Selection sets in Visual Lisp
« Reply #5 on: September 17, 2018, 11:40:11 AM »
Thanks guys.
Actually I already found a way around my problem. However, I am continuing out of curiosity.

I could make function from Grrr1337 work, but still not getting how to deal with function from kpblc

Code - Auto/Visual Lisp: [Select]
  1. (defun kpblc (obj-lst / adoc name selset)
  2.         name "TempSelSet"
  3.         ) ;_ end of setq
  4.   (vl-catch-all-apply (function (lambda () (vla-delete (vla-item (vla-get-selectionsets adoc) name))))
  5.                       ) ;_ end of vl-catch-all-apply
  6.   (setq selset (vla-add (vla-get-selectionsets adoc) name))
  7.   (vla-additems selset
  8.                 (vlax-make-variant
  9.                   (vlax-safearray-fill (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj-lst)))) obj-lst)
  10.                   ) ;_ end of vlax-make-variant
  11.                 ) ;_ end of vla-additems
  12.   ) ;_ end of defun
  13.  
  14.  
  15. (defun oSS->oL ( oSS / oL )
  16.   (and
  17.     (eq 'VLA-OBJECT (type oSS))
  18.     (vlax-property-available-p oSS 'Name)
  19.     (vlax-for o oSS (setq oL (cons o oL)))
  20.     ); and
  21.   oL
  22.   ); defun oSS->oL
  23.  
  24.  
  25.  
  26. (defun c:test2 (/ sel blkselection vlablkselection)
  27.  
  28.   (setq blkselection (ssget '((0 . "INSERT")(66 . 1))))
  29.   (setq vlablkselection (LM:ss->vla blkselection))
  30.  
  31.   (oSS->oL sel);works fine
  32.   (setq sel (kpblc vlablkselection));doesn't work
  33.   )
  34.  
« Last Edit: September 17, 2018, 12:02:34 PM by Red Nova »

ribarm

  • Gator
  • Posts: 3287
  • Marko Ribar, architect
Re: Selection sets in Visual Lisp
« Reply #6 on: September 17, 2018, 11:46:27 AM »
Where did you find variable lst defined?

Have you tried :

Code - Auto/Visual Lisp: [Select]
  1. (setq sel (kpblc vlablkselection))
  2.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Red Nova

  • Newt
  • Posts: 69
Re: Selection sets in Visual Lisp
« Reply #7 on: September 17, 2018, 12:03:41 PM »
Where did you find variable lst defined?

Have you tried :

Code - Auto/Visual Lisp: [Select]
  1. (setq sel (kpblc vlablkselection))
  2.  

Yes, I have tried that.
I corrected my code on previous post.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Selection sets in Visual Lisp
« Reply #8 on: September 17, 2018, 12:31:16 PM »
@Grrr1337:
I understand what you are doing there: working around the missing ObjectName property. But the selection set object has some unique methods, checking for those would be more straightforward.
« Last Edit: September 17, 2018, 12:45:13 PM by roy_043 »

ribarm

  • Gator
  • Posts: 3287
  • Marko Ribar, architect
Re: Selection sets in Visual Lisp
« Reply #9 on: September 17, 2018, 12:52:25 PM »
Have you tried :

Quote
(defun kpblc (obj-lst / adoc name selset)
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object))
        name "TempSelSet"
        ) ;_ end of setq
  (vl-catch-all-apply (function (lambda () (vla-delete (vla-item (vla-get-selectionsets adoc) name))))
                      ) ;_ end of vl-catch-all-apply
  (setq selset (vla-add (vla-get-selectionsets adoc) name))
  (vla-additems selset
                (vlax-make-variant
                  (vlax-safearray-fill (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj-lst)))) obj-lst)
                  ) ;_ end of vlax-make-variant
                ) ;_ end of vla-additems
  selset
  ) ;_ end of defun
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Selection sets in Visual Lisp
« Reply #10 on: September 17, 2018, 02:03:47 PM »
@Grrr1337:
I understand what you are doing there: working around the missing ObjectName property. But the selection set object has some unique methods, checking for those would be more straightforward.

Initially I thought about what you wrote, Roy - since the missing ObjectName property.
But in order to keep the subfoo simplier - I've decided to avoid them and just errortrap with the vla-item method.


Ofcourse one could follow your suggestion -

Code - Auto/Visual Lisp: [Select]
  1. ; (CheckIfvlaSS (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))) >> T
  2. ; (CheckIfvlaSS (vlax-ename->vla-object (car (entsel)))) >> nil
  3. (defun CheckIfvlaSS ( SS )
  4.   (and
  5.     (eq 'VLA-OBJECT (type SS))
  6.       '(Application Count Name)
  7.     )
  8.       '(AddItems Clear Delete Erase Highlight Item RemoveItems Select SelectAtPoint SelectByPolygon SelectOnScreen Update)
  9.     )
  10.   ); and
  11. ); defun
(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

Red Nova

  • Newt
  • Posts: 69
Re: Selection sets in Visual Lisp
« Reply #11 on: September 17, 2018, 02:07:33 PM »
Have you tried :

Quote
(defun kpblc (obj-lst / adoc name selset)
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object))
        name "TempSelSet"
        ) ;_ end of setq
  (vl-catch-all-apply (function (lambda () (vla-delete (vla-item (vla-get-selectionsets adoc) name))))
                      ) ;_ end of vl-catch-all-apply
  (setq selset (vla-add (vla-get-selectionsets adoc) name))
  (vla-additems selset
                (vlax-make-variant
                  (vlax-safearray-fill (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj-lst)))) obj-lst)
                  ) ;_ end of vlax-make-variant
                ) ;_ end of vla-additems
  selset
  ) ;_ end of defun

Thanks. Silly me ))

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Selection sets in Visual Lisp
« Reply #12 on: September 18, 2018, 03:25:37 AM »
@Grrr1337:
You are going a bit overboard there. Checking one unique method should be enough. Note that I disagree with the error-checking in your oSS->oL function. But that has been discussed before.