TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: A_LOTA_NOTA on August 17, 2007, 09:44:00 AM

Title: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 09:44:00 AM
Is it possible to call the “SAVEAS” dialogue?

I’ve got a situation where I want to get the drawing name. So I want to test to make sure the drawing has been saved first. If not I would like to “SAVEAS” then get the drawing name.

Thanks
Title: Re: Save Drawing
Post by: Guest on August 17, 2007, 09:50:29 AM
(getvar "DWGTITLED")

If it = 0, the drawing hasn't been saved yet.
It if = 1, the drawing has already been saved.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 09:57:48 AM
(getvar "DWGTITLED")

If it = 0, the drawing hasn't been saved yet.
It if = 1, the drawing has already been saved.

Thanks Matt but I knew that much. What I'm having a problem with it the "SAVEAS" part. If I just do a "Command SAVEAS" the user is not given a dialog box. I would like the "SAVEAS" dialog box to be displayed!
Title: Re: Save Drawing
Post by: ronjonp on August 17, 2007, 10:00:29 AM
Look at (setvar 'filedia 1)
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 10:04:29 AM
Look at (setvar 'filedia 1)

It's set to 1!
Title: Re: Save Drawing
Post by: Guest on August 17, 2007, 10:11:52 AM
So what exactly is happening when the user does a SAVEAS?
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 10:34:40 AM
So what exactly is happening when the user does a SAVEAS?

If I click on "File" then "SAVEAS" everything works fine! But if I add (command ".SAVEAS") to my code it doesn't give a dialog box. So I thought I must be coding it wrong.
Title: Re: Save Drawing
Post by: Guest on August 17, 2007, 10:38:30 AM
Is filedia set to 0 somewhere in your code prior to the saveas?
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 10:44:00 AM
No, I can have

Code: [Select]
(defun c:TEST ()
  (setvar 'filedia 1)
  (command ".SAVEAS")
  )

& I still get the command line version!
Title: Re: Save Drawing
Post by: Willie on August 17, 2007, 10:47:56 AM
Try


(defun c:TEST ()
  (initdia)
  (command ".SAVEAS")
  )
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 10:49:15 AM
Try


(defun c:TEST ()
  (initdia)
  (command ".SAVEAS")
  )

That did it!! Thanks everyone!!!!
Title: Re: Save Drawing
Post by: Guest on August 17, 2007, 10:49:24 AM
No, I can have

Code: [Select]
(defun c:TEST ()
  (setvar 'filedia 1)
  (command ".SAVEAS")
  )

& I still get the command line version!

Part of the problem is with the second line of code...

(setvar 'filedia 1) should be (setvar "filedia" 1)

Notice the quotes. . . . . . . . . . . . .^ ^ ^
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 10:58:51 AM
No, I can have

Code: [Select]
(defun c:TEST ()
  (setvar 'filedia 1)
  (command ".SAVEAS")
  )

& I still get the command line version!

Part of the problem is with the second line of code...

(setvar 'filedia 1) should be (setvar "filedia" 1)

Notice the quotes. . . . . . . . . . . . .^ ^ ^

Try it my way, I think you will get the same results!

Willie fixed my problem.
Title: Re: Save Drawing
Post by: Guest on August 17, 2007, 11:02:15 AM
No, I can have

Code: [Select]
(defun c:TEST ()
  (setvar 'filedia 1)
  (command ".SAVEAS")
  )

& I still get the command line version!

Part of the problem is with the second line of code...

(setvar 'filedia 1) should be (setvar "filedia" 1)

Notice the quotes. . . . . . . . . . . . .^ ^ ^

Try it my way, I think you will get the same results!

Willie fixed my problem.

Huh... no $*#%.  I never knew that nor have I ever seen it done that way (until today).

Cool.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 11:16:12 AM
No, I can have

Code: [Select]
(defun c:TEST ()
  (setvar 'filedia 1)
  (command ".SAVEAS")
  )

& I still get the command line version!

Part of the problem is with the second line of code...

(setvar 'filedia 1) should be (setvar "filedia" 1)

Notice the quotes. . . . . . . . . . . . .^ ^ ^

Try it my way, I think you will get the same results!

Willie fixed my problem.

Huh... no $*#%.  I never knew that nor have I ever seen it done that way (until today).

Cool.

Only saves one key stroke but I like it better!
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 07:51:17 PM
Try


(defun c:TEST ()
  (initdia)
  (command ".SAVEAS")
  )

This worked good for "SAVEAS" but now I have the same problem when closing a drawing. If I type close at the command line I get the dialog asking if I want to save changes. But if I use Close in a lisp it prompts me to save at te command line.
Title: Re: Save Drawing
Post by: Keith™ on August 17, 2007, 08:46:09 PM
the mechanism is the same for the save/saveas dialogs
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 11:30:24 PM
the mechanism is the same for the save/saveas dialogs

So may be I need to run some sort of test to see if the drawing needs to be saved before closing it?
Title: Re: Save Drawing
Post by: Kerry on August 17, 2007, 11:33:32 PM

Have a look at the DBMOD system variable.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 11:36:08 PM

Have a look at the DBMOD system variable.

Thank you! Looks like that will work!

added: After more thought I shouldn't need to do any testing. If I tell AutoCAD I want to close a drawing it does the testing for me. But I don't get the "Save Changes Yes No Cancel" dialog.
Title: Re: Save Drawing
Post by: Kerry on August 17, 2007, 11:45:39 PM

You should also look at at the DWGTITLED variable
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 11:49:52 PM

You should also look at at the DWGTITLED variable

I have that one in my code & everything works great. But I had to make my own DCL for the "Do you want to save changes". But I shouldn't have to do that! AutoCAD knows the changes have been made & prompts me to save. But it does it at the command line, not with the DCL like it would if I typed "Close" at the command prompt.
Title: Re: Save Drawing
Post by: Kerry on August 17, 2007, 11:52:17 PM
added: ... But I don't get the "Save Changes Yes No Cancel" dialog.

Have a look at the initdia Help .. some commands do not make use of it.

reading the help now, I note that .SaveAs is not mentioned, so it's usage IS a bonus. ;-)
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 17, 2007, 11:58:24 PM
Kerry,

 I just learned about "Initdia" at the beginning of this thread. When I had the same problem with "SAVEAS" as I'm having with "CLOSE". It fixed the saveas problem but doesn't seam to change close.

I have looked in the help file for '06 & '08. Didn't find it in either one.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 18, 2007, 12:02:59 AM
If I use the following code I just get prompted at the command line to save the drawing.

Code: [Select]
(defun c:TEST ()
  (initdia)
  (command ".Close" puase)
  )
Title: Re: Save Drawing
Post by: Kerry on August 18, 2007, 12:04:21 AM
I'm interested (from a design perspective) why you  or your users would not be happy with the default command line Prompt.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 18, 2007, 12:09:10 AM
I'm interested (from a design perspective) why you  or your users would not be happy with the default command line Prompt.

It would work fine. But if I type "Close" at the command prompt or click "file" then "exit", AutoCAD gives a dialog asking if I would like to save changes. So in trying to make my program act like a standard AutoCAD command.

Just picky I guess.....
Title: Re: Save Drawing
Post by: Kerry on August 18, 2007, 12:11:16 AM
If I use the following code I just get prompted at the command line to save the drawing.

Code: [Select]
(defun c:TEST ()
  (initdia)
  (command ".Close" puase)
  )

I haven't tested, I'll leave that to you, but I don't believe you need the 'pause ...
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 18, 2007, 12:16:19 AM
If I use the following code I just get prompted at the command line to save the drawing.

Code: [Select]
(defun c:TEST ()
  (initdia)
  (command ".Close" puase)
  )

I haven't tested, I'll leave that to you, but I don't believe you need the 'pause ...

No, the pause is not need. I was posting the code more for the fact that I tried INITDIA and it doesn't change anything. And so someone could see a part of what I was trying to do & could may be point out why I don't get the dialog box like I do if entering "close" at the comand prompt.
Title: Re: Save Drawing
Post by: A_LOTA_NOTA on August 18, 2007, 09:57:56 AM
Got it!!
Code: [Select]
(defun c:TEST1 ()
  (vla-sendcommand
    (vla-get-activedocument (vlax-get-acad-object))
    ".close ")
  )