Author Topic: ssadd into Visula Lisp  (Read 3509 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
ssadd into Visula Lisp
« on: March 23, 2013, 12:15:19 PM »
Hello masters  :wink:

Is there a way to convert the ssadd function into Visual Lisp ? I think the function vla-additems is the one but I don't know how to deal with it .

Code: [Select]
(setq ss (ssadd))

(if (setq sel (ssget))
  (repeat (setq int (sslength sel))
    (ssadd (ssname sel (setq int (1- int))) ss)
  )
)


Many thanks in Advance .

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssadd into Visula Lisp
« Reply #1 on: March 23, 2013, 12:52:58 PM »
Perhaps if you explain what you are trying to do.
(setq sel (ssget))
(setq ss sel)

If ss is an existing selection set.
Code: [Select]
(setq sel (ssget))
(defun ss->ss (ss1 ss2 / i ename)
  (and (eq 'pickset (type ss1))(eq 'pickset (type ss2))
       (setq i -1)
       (while (setq ename (ssname ss1 (setq i (1+ i))))
         (ssadd ename ss2)))
  )
  ss2
)
;; (setq ss (ssadd))
(setq ss (ss->ss sel ss))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

fixo

  • Guest
Re: ssadd into Visula Lisp
« Reply #2 on: March 23, 2013, 01:11:02 PM »
Found this one by Peter Jamtgaard,
see if this is will be satisfy your needs:
Code: [Select]
; Written By: Peter Jamtgaard 2002
; This program will convert a Autolisp selection set into
; a named selection set that can be accessed by ActiveX
; or Visual Basic
 
(defun SS (SSET SSNAM / CNT EOBJ NEWSS SAFE SSET SSLST SSOBJ)
 (setq CNT   0
       SSOBJ (vla-get-selectionsets
              (vla-get-activedocument
               (vlax-get-acad-object)
              )
             )
 )
 (if (vl-catch-all-error-p
      (vl-catch-all-apply
       '(lambda (X)  (setq NEWSS (vla-add X SSNAM)))
                     (list SSOBJ)
      )
     )
  (progn
   (vla-delete (vla-item SSOBJ SSNAM))
   (setq NEWSS (vla-add  SSOBJ SSNAM))
  )
 )
 (if SSET
  (progn
   (setq SAFE (vlax-make-safearray vlax-vbObject (cons 0 (- (sslength
SSET) 1))))
   (repeat (sslength SSET)
    (setq EOBJ (vlax-ename->vla-object
                (ssname SSET CNT)
               )
          CNT  (1+ CNT)         
    )
    (setq SSLST (cons EOBJ SSLST))
   )
   (vlax-safearray-fill SAFE SSLST)
   (vla-additems NEWSS (variant SAFE))
  )
 )
 (princ (strcat "\nYou have created a selection set called " SSNAM))
 (prin1)
)
(princ "SS")
(prin1)

Coder

  • Swamp Rat
  • Posts: 827
Re: ssadd into Visula Lisp
« Reply #3 on: March 23, 2013, 02:41:01 PM »
Thanks fixo .

Can you please explain the code for me ?

Regards
« Last Edit: March 23, 2013, 02:56:38 PM by Coder »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssadd into Visula Lisp
« Reply #4 on: March 23, 2013, 03:27:47 PM »
« Last Edit: March 23, 2013, 03:31:14 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: ssadd into Visula Lisp
« Reply #5 on: March 23, 2013, 04:18:44 PM »
Hi,

Here's a simpler way to convert the active AutoLISP selection set to a COM/ActiveX one. 
This method is the only one I use, most of the time I rather use AutoLISP selection sets or lists.
Visual LISP selection sets and safearrays are boring to use and tend to make LISP as verbose as VBA.
Code - Auto/Visual Lisp: [Select]
  1.   ...
  2.   (vla-Delete ss) ; <- a COM selection set have to be released after used
  3. )
Speaking English as a French Frog

Coder

  • Swamp Rat
  • Posts: 827
Re: ssadd into Visula Lisp
« Reply #6 on: March 24, 2013, 08:58:37 AM »
Hello .

I have a few questions and hope that someone have willing to help me with them .  :wink:

As posted by fixo .

Code: [Select]
(vl-catch-all-error-p
        (vl-catch-all-apply '(lambda (x) (setq newss (vla-add x ssnam))) (list ssobj))
      )

1- the ssobj is added to the named selection set argument ( ssnam ) .
      and below in the same code , they deleted ssobj from the ssnam and after that they re-add it to the ssnam , this is odd to me ?

Code: [Select]
(vla-delete (vla-item ssobj ssnam))
(setq newss (vla-add  ssobj ssnam)))

2- What's the meaning of variant function ?

Code: [Select]
(vla-additems newss (variant safe))


Many thanks in advance .

fixo

  • Guest
Re: ssadd into Visula Lisp
« Reply #7 on: March 24, 2013, 01:57:02 PM »
1 Yes' you're right
2. variant is comes from VitalLisp,
it's equial to 'vlax-make-variant' function in VisualLisp

Coder

  • Swamp Rat
  • Posts: 827
Re: ssadd into Visula Lisp
« Reply #8 on: March 24, 2013, 02:06:39 PM »
1 Yes' you're right
2. variant is comes from VitalLisp,
it's equial to 'vlax-make-variant' function in VisualLisp

Thank you fixo for that clarification , it's very helpful . :)

Thanks to CAB and gile also .

Many thanks