Custom save command

Custom save command

owitzki
Enthusiast Enthusiast
1,865 Views
17 Replies
Message 1 of 18

Custom save command

owitzki
Enthusiast
Enthusiast

Hi Guys,

 

Can I ask you favor? I need a custom save command with 2 conditions:

 

If the 'measurement' is '0' (zero), settings will be psltscale = as is and ltscale = as is;

And if 'measurement' is '1' (one), settings will be psltscale = 1 and ltscale = 1

 

Should this topic already exist, please direct me to the appropriate forum.

 

Thanks & regards,

0 Likes
Accepted solutions (3)
1,866 Views
17 Replies
Replies (17)
Message 2 of 18

paullimapa
Mentor
Mentor
Accepted solution

(defun c:NewSave ()(if(not(zerop(getvar"measurement")))(progn(setvar"psltscale"1)(setvar"ltscale"1)(princ"\nPsLTScale & LTScale set to 1"))(princ"\nPsLTScale & LTScale left As Is."))(command"_.QSAVE")(princ))

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 18

scot-65
Advisor
Advisor
Are you trying to REDEFINE Qsave?

If so, write it as such that the first invoke will
do it's chore and successive calls will skip.

Or perhaps a reactor?

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 4 of 18

ActivistInvestor
Mentor
Mentor

@owitzki wrote:

Hi Guys,

 

Can I ask you favor? I need a custom save command with 2 conditions:

 

If the 'measurement' is '0' (zero), settings will be psltscale = as is and ltscale = as is;

And if 'measurement' is '1' (one), settings will be psltscale = 1 and ltscale = 1

 

Should this topic already exist, please direct me to the appropriate forum.

 

Thanks & regards,


You really don't want to redefine built-in commands for any reason. Doing that is usually more complicated than most attempts you'll find. For example, QSAVE will prompt for a filename if you invoke it on a new, unnamed file. If the file is already saved, it will do nothing (and in that case, your redefined command will change settings that it really shouldn't change).

 

Have you given any thought to how many ways a file can be saved?  If you use a vlr-beginSave reactor, it solves the problem in a more-reliable way. It can take whatever actions it needs to just before the file is saved, regardless of how that happens (e.g., SAVE, SAVEAS, SAVEALL, QUIT/CLOSE and answer yes, etc.).

 

A search of this forum for vlr-beginSave would probably turn up something you can adapt.

 

 

0 Likes
Message 5 of 18

owitzki
Enthusiast
Enthusiast

Thanks Paul it worked!

 

Regards,

0 Likes
Message 6 of 18

paullimapa
Mentor
Mentor
0 Likes
Message 7 of 18

owitzki
Enthusiast
Enthusiast

Just one more Paul, can we add to the first condition annotation scale of model space to be 1:1?

 

Thanks,

0 Likes
Message 8 of 18

paullimapa
Mentor
Mentor

It'll be adding this sequence of code (setvar "CANNOSCALE" "1:1") to the first condition:

 

The code will now look like this:

; NewSave.lsp command adds additional settings before executing a save

(defun c:NewSave ()

 (if(not(zerop(getvar"measurement")))

   (progn                                                 ; measurement = 1

     (setvar"psltscale"1)(setvar"ltscale"1)  ; set PS & LT scales to 1

     (setvar "CANNOSCALE" "1:1") ; set annotation 1:1

     (princ"\nPsLTScale & LTScale set to 1, Annotation Scale set 1:1")

   ) ; progn

   (princ"\nPsLTScale & LTScale left As Is.")  ; else

 ) ; if

 (command"_.QSAVE")(princ)

) ; defun

 

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 18

owitzki
Enthusiast
Enthusiast

Hi Paul,

 

Is this to perform the following conditions?

 

If the 'measurement' is '0' (zero), settings will be psltscale = as is, ltscale = as is and annotation scale for model space 1:1;

And if 'measurement' is '1' (one), settings will be psltscale = 1, ltscale = 1 and annotation scale for model space = as is

0 Likes
Message 10 of 18

paullimapa
Mentor
Mentor

Ok,then it's the other way:

 

The code will now look like this:

; NewSave.lsp command adds additional settings before executing a save

(defun c:NewSave ()

 (if(not(zerop(getvar"measurement")))

   (progn                                                 ; measurement = 1

     (setvar"psltscale"1)(setvar"ltscale"1)  ; set PS & LT scales to 1

     (princ"\nPsLTScale & LTScale set to 1")

   ) ; progn

  (progn

    (setvar "CANNOSCALE" "1:1") ; set annotation 1:1

    (princ"\nPsLTScale & LTScale left As Is., Annotation Scale set 1:1)  

  ) ; progn else

 ) ; if

 (command"_.QSAVE")(princ)

) ; defun

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 18

owitzki
Enthusiast
Enthusiast

It says

 

Command: error: malformed string on input

0 Likes
Message 12 of 18

paullimapa
Mentor
Mentor
Accepted solution

Oops, I forgot a quote " mark at the end of this line after 1:1:

(princ"\nPsLTScale & LTScale left As Is., Annotation Scale set 1:1") 

I've attached the corrected version.

With the comments in the code this should make it easier for you to understand what's going on and even modify it on your own.

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 18

owitzki
Enthusiast
Enthusiast

Perfect this is it!

 

Thanks again, appreciate it much 🙂

0 Likes
Message 14 of 18

paullimapa
Mentor
Mentor
0 Likes
Message 15 of 18

owitzki
Enthusiast
Enthusiast

Hi Paul,

 

The lisp is working but in some drawings, when I invoke this custom save command in model space it's fine (see image 2), but in paper space it says error see Image 1.

 

 

in paper spacein paper spacein model spacein model space

In any case, I can still use it.

 

 

0 Likes
Message 16 of 18

paullimapa
Mentor
Mentor
Accepted solution

Ok, I changed the code so that it won't execute the command if it's in Paperspace by adding a check for CVPORT (see attached revised zip).

CVPORT is always = 1 in Paperspace.  So only when CVPORT is greater than 1 then the CANNOSCALE command will be executed.

This should eliminate the error message.  Here's the line of code that I changed:

 

(if(> (getvar"cvport") 1)(setvar "CANNOSCALE" "1:1"))

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 17 of 18

owitzki
Enthusiast
Enthusiast

It's good now Paul.Smiley Happy

 

Thanks again & regards

0 Likes
Message 18 of 18

paullimapa
Mentor
Mentor
0 Likes