+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Full Member
    Using
    Civil 3D 2013
    Join Date
    Apr 2014
    Posts
    45

    Default select previous group via lisp problem...

    Registered forum members do not see this ad.

    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 do it?

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

  2. #2
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    287

    Default

    Hi there.

    Sometimes you get more views by directly posting the code (of course between code tags to avoid the wrath of gods and terminators...) instead of attaching it, forcing users to login to actually see it.

    So, if I understood correctly, the only thing you are trying to achieve is to erase the spline, and end up with the selection originally made by the lisp. Since in the lisp there was already a var (e) containing the <ename> of the spline, it can easilly be achieved by simply adding the line I added in green, deleting the spline just before the selection is made and returned. No need for extra mileage there!
    A little side note: It can be irritating to have a lisp routine that once executed change settings without reverting them back at the end. Best practice: look and store its original value in a variable, change the var as needed, then change it back using its original value from the created variable. (See added code in red).

    Code:
    ;;; Make Lasso Selection (draw spline and Select Objects Within/Crossing it)
    ;;; Special thanks to Alan J. Thompson
    
    
    (defun c:SWC (/ _pac add ss i e temp it o a b pts tempC i3 ec)
      ;; Select Objects Within/Crossing Curve
      ;; Alan J. Thompson, 03.31.11
      ;; Slightly modified by Igal Averbuh 2017 (added option for splines)
      ;; Slightly modified by Jef! 2017 (erased spline + osmode restoration)
      (vl-load-com)
    
      (defun _pac (e / l v d lst)
        (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
        (while (< (setq d (+ d v)) l)
          (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
        )
      )
    
      (initget 0 "Crossing Within")
      (setq *SWC:Opt*
             (cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] <"
                                      (cond (*SWC:Opt*)
                                            ((setq *SWC:Opt* "Crossing"))
                                      )
                                      ">: "
                              )
                    )
                   )
                   (*SWC:Opt*)
             )
      )
      (princ "\nSelect closed curves to select object(s) within: ")
      (if (setq add (ssadd)
                ss  (ssget "L"
                    )
          )
        (progn (repeat (setq i (sslength ss))
                 (if (setq temp (ssget "_WP" (_pac (setq e (ssname ss (setq i (1- i)))))))
                   (repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
                 )
    
                 (if (eq *SWC:Opt* "Crossing")
                   (progn (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'a 'b)
                          (setq pts (mapcar 'vlax-safearray->list (list a b)))
                          (if (setq tempC (ssget "_C"
                                                 (list (caar pts) (cadar pts) 0.)
                                                 (list (caadr pts) (cadadr pts) 0.)
                                          )
                              )
                            (repeat (setq i3 (sslength tempC))
                              (if (vlax-invoke
                                    o
                                    'Intersectwith
                                    (vlax-ename->vla-object (setq ec (ssname tempC (setq i3 (1- i3)))))
                                    acExtendNone
                                  )
                                (ssadd ec add)
                              )
                            )
                          )
                   )
                 )
               )
               (vla-delete (vlax-ename->vla-object e))
               (sssetfirst nil add)
               (ssget "_I")
        )
      )
      (princ)
    )
    
    (defun C:LAT ( / oldosmode )
      (setq oldosmode (getvar 'osmode))
      (setvar "osmode" 16384)
      (command "_.spline")
      (while (> (getvar "CmdActive") 0)
        (command pause)
      )
      (c:swc)
      (if oldosmode
          (setvar 'osmode oldosmode)
      )
      (princ)
    )
    Cheers!
    Different goal also quite often means different path...

  3. #3
    Full Member
    Using
    Civil 3D 2013
    Join Date
    Apr 2014
    Posts
    45

    Default

    Thank you Jef! for your notes an your approach

  4. #4
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    287

    Default

    Registered forum members do not see this ad.

    You're welcome!
    Different goal also quite often means different path...

Similar Threads

  1. Select previous
    By Rainy-Day in forum AutoCAD Drawing Management & Output
    Replies: 8
    Last Post: 3rd Jun 2016, 12:20 pm
  2. Create Last Select & Previous by LISP. Can be done ???
    By Deby Ferdian in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 15th Mar 2016, 07:59 pm
  3. Replies: 9
    Last Post: 12th Jan 2016, 01:48 pm
  4. select previous in vba
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 21st Jan 2009, 01:25 pm
  5. Lisp that will select layer and draw VP and go back to previous layer
    By matthewrussell in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 20th Jan 2009, 09:21 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts