Author Topic: select previous group via lisp problem...  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
select previous group via lisp problem...
« on: February 22, 2017, 04:32:32 AM »
Hi folks.


This lisp ( attached one) can draw spline ,Select Objects Within/Crossing it and erase spline used for selection.


In this case I need to reselect previoustly selected entities within spline and than I created group from these objects..


But now I need to select previous group.. It's possible if I use GROUP command from command line, but problematical for me to do it via lisp


Do you have any idea how to do it?


I appreciate your quick response and the time you spent in helping me out. Thanks

 

ronjonp

  • Needs a day job
  • Posts: 7527
Re: select previous group via lisp problem...
« Reply #1 on: February 22, 2017, 10:59:29 AM »
Maybe this will help:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:swc (/ _addgroup _pac add e i ss temp)
  2.   ;; Select Objects Within/Crossing Curve
  3.   ;; Alan J. Thompson, 03.31.11
  4.   ;; Slightly modified by Igal Averbuh 2017 (added option for splines)
  5.   ;; RJP simplified & added groups 02.22.2017
  6.   (defun _pac (e / l v d lst)
  7.     (setq d (- (setq v (/ (setq l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) 500.))))
  8.     (while (< (setq d (+ d v)) l) (setq lst (cons (vlax-curve-getpointatdist e d) lst)))
  9.   )
  10.   (defun _addgroup (listofobjects / grp grps name)
  11.     ;; Check that all items in the list are vla-objects
  12.     (if (and (vl-every '(lambda (x) (eq (type x) 'vla-object)) listofobjects)
  13.         )
  14.       (progn (setq grp (vla-add grps "*"))
  15.              (vlax-invoke grp 'appenditems listofobjects)
  16.              listofobjects
  17.       )
  18.     )
  19.   )
  20.   (initget 0 "Crossing Within")
  21.   (setq *swc:opt*
  22.          (cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] <"
  23.                                   (cond (*swc:opt*)
  24.                                         ((setq *swc:opt* "Crossing"))
  25.                                   )
  26.                                   ">: "
  27.                           )
  28.                 )
  29.                )
  30.                (*swc:opt*)
  31.          )
  32.   )
  33.   (princ "\nSelect closed curves to select object(s) within: ")
  34.   (if (setq add (ssadd)
  35.             ss  (ssget ":L" '((0 . "SPLINE")))
  36.       )
  37.     (progn
  38.       (repeat (setq i (sslength ss))
  39.         ;; Must be visible on screen for point selection to work
  40.         (if (setq temp (ssget (if (eq *swc:opt* "Crossing")
  41.                                 "_CP"
  42.                                 "_WP"
  43.                               )
  44.                               (_pac (setq e (ssname ss (setq i (1- i)))))
  45.                        )
  46.             )
  47.           (progn
  48.             ;; Remove boundary from selection so it won't get grouped
  49.             (ssdel e temp)
  50.             ;; Delete boundary
  51.             (entdel e)
  52.             ;; Group objects
  53.             (_addgroup
  54.               (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex temp))))
  55.             )
  56.             ;; Highlight selection
  57.             ;; (sssetfirst nil temp)
  58.           )
  59.         )
  60.       )
  61.     )
  62.   )
  63.   (princ)
  64. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: select previous group via lisp problem...
« Reply #2 on: February 23, 2017, 02:44:04 AM »
Thank you ronjonp for your significant approach
I did a little modification of this code: (see attached one)
1. code added to main routine
2. your code was slightly modified - now spline erased automatically
3. highlighting of selected objects was turned ON
Thank you again for cooperation



ronjonp

  • Needs a day job
  • Posts: 7527
Re: select previous group via lisp problem...
« Reply #3 on: February 23, 2017, 11:03:23 AM »
Thank you ronjonp for your significant approach
I did a little modification of this code: (see attached one)
1. code added to main routine
2. your code was slightly modified - now spline erased automatically
3. highlighting of selected objects was turned ON
Thank you again for cooperation
Glad it worked for you.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC