Custom Save command help

Custom Save command help

Anonymous
Not applicable
920 Views
7 Replies
Message 1 of 8

Custom Save command help

Anonymous
Not applicable

I am currently altering our work save config to better suit our workflow but I am struggling to make one change.

 

The current command is this

 

(command"_.Undefine""_.QSave") ; Undefine the QSave command
; define a custom Save command that executes Propulate command and then save
(defun c:Qsave ()
 (command"_PSPACE""")
 (command"_.layout""_Set""") ; Move to LAYOUT 1
 (command"_.regen")
 (command"_.Propulate""_Update""_Current") ; run Propulate command
 (command"_.ZOOM""_E") ; zoom extents before save
 (command"_.QSave""""")(princ) ; run standard save command
)

 

I want to add lines to it that will check if the current drawing has a viewport in, if it does not then I just want it to run a regular save command without zooming or running propulate. Some of our drawings are just model files and having it run the extra commands are just unneccesary and are causing issues.

0 Likes
Accepted solutions (1)
921 Views
7 Replies
Replies (7)
Message 2 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:

 

I want to add lines to it that will check if the current drawing has a viewport in, if it does not then I just want it to run a regular save command without zooming or running propulate. Some of our drawings are just model files and having it run the extra commands are just unneccesary and are causing issues.


One way:

 

(setq ss (ssget "_X" (list '(0 . "VIEWPORT")))
      layt_lst (layoutlist))
(if (/= (sslength ss) (length layt_lst))
  ;; do the layout commands
  ;; do just the save
  )

 

 

I hope this helps

Henrique

EESignature

0 Likes
Message 3 of 8

Anonymous
Not applicable
Thank you, would I add it in at the beginning just under this line?

(defun c:Qsave ()
0 Likes
Message 4 of 8

hmsilva
Mentor
Mentor

You 're welcome.

Try

 

(command"_.Undefine""_.QSave") ; Undefine the QSave command
; define a custom Save command that executes Propulate command and then save
(defun c:Qsave ( / layt_lst ss)
  (setq ss (ssget "_X" (list '(0 . "VIEWPORT")))
      layt_lst (layoutlist))
(if (/= (sslength ss) (length layt_lst))
  (progn
 (command"_PSPACE""")
 (command"_.layout""_Set""") ; Move to LAYOUT 1
 (command"_.regen")
 (command"_.Propulate""_Update""_Current") ; run Propulate command
 (command"_.ZOOM""_E") ; zoom extents before save
 (command"_.QSave""""")(princ) ; run standard save command
 );; progn
 (command"_.QSave""""")(princ) ; run standard save command
  );; if
  (princ)
)

 

Henrique

EESignature

0 Likes
Message 5 of 8

Anonymous
Not applicable
Just getting a syntax error 😕
0 Likes
Message 6 of 8

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:
Just getting a syntax error 😕

Code revised

(command"_.Undefine""_.QSave") ; Undefine the QSave command
; define a custom Save command that executes Propulate command and then save
(defun c:Qsave ( / layt_lst ss)
  (setq ss (ssget "_X" (list '(0 . "VIEWPORT")))
      layt_lst (layoutlist))
(if (/= (sslength ss) (length layt_lst))
  (progn
 (command"_PSPACE""")
 (command"_.layout""_Set""") ; Move to LAYOUT 1
 (command"_.regen")
 (command"_.Propulate""_Update""_Current") ; run Propulate command
 (command"_.ZOOM""_E") ; zoom extents before save
 (command"_.QSave") ; run standard save command
 );; progn
 (command"_.QSave") ; run standard save command
  );; if
  (princ)
)

 

Henrique

EESignature

0 Likes
Message 7 of 8

Anonymous
Not applicable
Perfect! Thank you! Any chance you could comment on it and how it works? I am trying to learn this stuff so that would be greatly appreciated. If not then thank you anyway, huge help!
0 Likes
Message 8 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:
Perfect! Thank you! Any chance you could comment on it and how it works? I am trying to learn this stuff so that would be greatly appreciated. If not then thank you anyway, huge help!

You're welcome, MDub!

 

From the code:

(defun c:Qsave ( / layt_lst ss)
  ;; create a selection set with "VIEWPORT" entities
  ;; each layout is a "VIEWPORT"
  (setq ss (ssget "_X" (list '(0 . "VIEWPORT")))
  ;; create a layout list
      layt_lst (layoutlist))
  ;; test function...
  ;; test if number of layouts is not equal to
  ;; number of layouts
  ;; if number is not the same, there are VIEWPORTS
(if (/= (sslength ss) (length layt_lst))
  (progn;; if true the test function, do this
 (command"_PSPACE""")
 (command"_.layout""_Set""") ; Move to LAYOUT 1
 (command"_.regen")
 (command"_.Propulate""_Update""_Current") ; run Propulate command
 (command"_.ZOOM""_E") ; zoom extents before save
 (command"_.QSave") ; run standard save command
 );; progn
  ;; if not true the test function, do this
 (command"_.QSave") ; run standard save command
  );; if
  (princ)
)

 

As I had previously said, this test function is one of several ways to do the test, another could be just test a "VIEWPORT" selection set, using a filter for VPid "dxf 69",

(if (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (69 . 1))))

 test for a selection set with an id greater than 1 (1 is the "LAYOUT"), and the rest of the code would be the same.

 

Hope that helps

Henrique

 

 

EESignature

0 Likes