TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on March 23, 2013, 12:15:19 PM

Title: ssadd into Visula Lisp
Post by: Coder 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 .
Title: Re: ssadd into Visula Lisp
Post by: CAB 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))
Title: Re: ssadd into Visula Lisp
Post by: fixo 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)
Title: Re: ssadd into Visula Lisp
Post by: Coder on March 23, 2013, 02:41:01 PM
Thanks fixo .

Can you please explain the code for me ?

Regards
Title: Re: ssadd into Visula Lisp
Post by: CAB on March 23, 2013, 03:27:47 PM
So that's what you are after.

Here is some old code from Jeff.
http://www.theswamp.org/index.php?topic=2133.msg27500#msg27500
http://www.theswamp.org/index.php?topic=5342.msg65947#msg65947
Title: Re: ssadd into Visula Lisp
Post by: gile 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. )
Title: Re: ssadd into Visula Lisp
Post by: Coder 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 .
Title: Re: ssadd into Visula Lisp
Post by: fixo 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
Title: Re: ssadd into Visula Lisp
Post by: Coder 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