Visual LISP, AutoLISP and General Customization

Reply
Contributor
Gustavo_Bernardi
Posts: 20
Registered: ‎05-30-2009
Message 1 of 7 (273 Views)

Filter if the ssget is empty

273 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

 

 

*Expert Elite*
hmsilva
Posts: 2,668
Registered: ‎12-17-2004
Message 2 of 7 (260 Views)

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

Contributor
Gustavo_Bernardi
Posts: 20
Registered: ‎05-30-2009
Message 3 of 7 (222 Views)

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

*Expert Elite*
hmsilva
Posts: 2,668
Registered: ‎12-17-2004
Message 4 of 7 (217 Views)

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

 

*Expert Elite*
hmsilva
Posts: 2,668
Registered: ‎12-17-2004
Message 5 of 7 (206 Views)

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

Contributor
Gustavo_Bernardi
Posts: 20
Registered: ‎05-30-2009
Message 6 of 7 (192 Views)

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.

*Expert Elite*
hmsilva
Posts: 2,668
Registered: ‎12-17-2004
Message 7 of 7 (186 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community