• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Contributor
    Posts: 16
    Registered: ‎05-30-2009

    Filter if the ssget is empty

    134 Views, 6 Replies
    01-23-2013 12:34 PM

    Hello all.

    I wonder if I have to check if the "ssget" is empty.

     

    I have a lisp to zoom extents in visible objects on the screen.

     

    My interest is to filter before applying:If I have selected objects, it zooms in these objects. If I'm not have selected objects, continue as it is today, applying a zoom in the visible scene.

     

    The result would be similar to a zoom of "3dsmax" (press the Z key)

     

    The atual code

    (defun c:ZOBJECTS(/ selectprev)
    (SETQ selectprev (SSGET "_P"))
    (command "._UCS" "View")
    (command "._zoom" "extents")
    (command ".__zoom" "object" "cross" "-1e99,-1e99" "1e99,1e99" "")
    (command "._UCS" "previous")
    (command "._select" selectprev "")
    )

     

     

    TIA

     

     

    Please use plain text.
    *Expert Elite*
    Posts: 1,216
    Registered: ‎12-17-2004

    Re: Filter if the ssget is empty

    01-23-2013 01:11 PM in reply to: Gustavo_Bernardi

    Gustavo_Bernardi,
    if I understood correctly

     

    (defun c:ZOBJECTS (/ selectprev)
      (if (setq selectprev (ssget "_P"))
        (progn
          (   );If you have selected objects
          (   );put here what you need to do
          (   );zoom wcs ...
        ); end of progn
        (progn
          (   );If you dont have selected objects
          (   );put here what you need to do
          (   ); zooms wcs ...
        ); end of progn
      ); end of if
    );end of ZOBJECTS

     

    hope that helps

    Henrique

    Please use plain text.
    Contributor
    Posts: 16
    Registered: ‎05-30-2009

    Re: Filter if the ssget is empty

    02-13-2013 10:38 AM in reply to: hmsilva

    Not exactly.
    The selectprev is just for safety. I capture the current "previous selection" to return it to autocad after the end of the command.

     

    I'll just put a piece of code that would change:

    (defun c:ZOBJECTS()
    (
    (if i have object selected);;here is my problem
    true:
    (command "._zoom" "O" ) false (progn (command "._UCS" "View") (command "._zoom" "extents") (command "._zoom" "object" "cross" "-1e99,-1e99" "1e99,1e99" "") (command "._UCS" "previous") ) ) )

     thanks

    Please use plain text.
    *Expert Elite*
    Posts: 1,216
    Registered: ‎12-17-2004

    Re: Filter if the ssget is empty

    02-13-2013 12:03 PM in reply to: Gustavo_Bernardi
    (defun c:ZOBJECTS (/ selectprev)
      (if (setq selectprev (ssget "_P"))
        (command "._zoom" "O" selectprev "")
        (progn
          (command "._UCS" "View")
          (command "._zoom" "extents")
          (command "._zoom"	"object" "cross" "-1e99,-1e99" "1e99,1e99" "")
          (command "._UCS" "previous")
        ); end of progn
      ); end of if
    );end of ZOBJECTS

     Henrique

     

    Please use plain text.
    *Expert Elite*
    Posts: 1,216
    Registered: ‎12-17-2004

    Re: Filter if the ssget is empty

    02-13-2013 01:59 PM in reply to: Gustavo_Bernardi

    Gustavo_Bernardi,

    with "ssget" and "_P", will select the previous selection set.

    The previous selection set, only becomes empty when, at least, one of the selected elements is removed from the drawing, for example, with erase, pedit, or when one object is erased.

    If you use a command that is necessary select an object, such as rotate or move, these objects become the last selected objects, and when you use your code will be made a zoom to these objects.

     

    When you have written "if i have object selected" did you mean, objects selected and gripped, if so try this code

     

    (defun c:test (/ ss)
      (if (setq ss (car (cdr (ssgetfirst))))
        (command "._zoom" "O" ss "")
        (progn
          (command "._UCS" "View")
          (command "._zoom" "extents")
          (command "._zoom"	"object" "cross" "-1e99,-1e99" "1e99,1e99" "")
          (command "._UCS" "previous")
        );; progn
      );; if
    )

     

    hope that helps

    Henrique

    Please use plain text.
    Contributor
    Posts: 16
    Registered: ‎05-30-2009

    Re: Filter if the ssget is empty

    02-15-2013 12:36 PM in reply to: hmsilva
    (defun c:zobjects (/ ss)
    (if (setq ss (car (cdr (ssgetfirst))))
    (command "._zoom" "O" ss "")
    (progn
    (SETQ selectprev (SSGET "_P"));;I capture the actual previous
    (command "._UCS" "View")
    (command "._zoom" "extents")
    (command "._zoom" "object" "cross" "-1e99,-1e99" "1e99,1e99" "");;this is the actual previous selection (and I do not want it)
    (command "._UCS" "previous")
    (command "._select" selectprev "");;I return the objects to the selection previous
    );; progn
    );; if
    )

    Henrique, thanks for your help!

     

    Now works fine...

     

    but still kept the selectprev, see his function described in the code.

    Please use plain text.
    *Expert Elite*
    Posts: 1,216
    Registered: ‎12-17-2004

    Re: Filter if the ssget is empty

    02-15-2013 01:02 PM in reply to: Gustavo_Bernardi

    You're welcome, Gustavo_Bernardi

    glad you got a solution

     

    Henrique

    Please use plain text.