Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filter if the ssget is empty

6 REPLIES 6
Reply
Message 1 of 7
Gustavo_Bernardi
1584 Views, 6 Replies

Filter if the ssget is empty

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

 

 

6 REPLIES 6
Message 2 of 7
hmsilva
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

EESignature

Message 3 of 7
Gustavo_Bernardi
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

Message 4 of 7
hmsilva
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

 

EESignature

Message 5 of 7
hmsilva
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

EESignature

Message 6 of 7
Gustavo_Bernardi
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.

Message 7 of 7
hmsilva
in reply to: Gustavo_Bernardi

You're welcome, Gustavo_Bernardi

glad you got a solution

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost