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

SAVEAS in AutoLISP

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
3744 Views, 12 Replies

SAVEAS in AutoLISP

I found this "saveas" routine online @ http://forums.augi.com/showthread.php?t=50250

(DEFUN c:sas ()
(COMMAND "_saveas" "" "~")
(PRINC "\nSaveAs Complete:")
(PRINC)
) ;_ end of DEFUN

This routine pops up the saveas dialogue box. Does anybody know a way where I can specify the saveas path in the routine?
12 REPLIES 12
Message 2 of 13
devitg
in reply to: Anonymous

(setq file (strcat (getvar "dwgprefix") filename)))
Message 3 of 13
Anonymous
in reply to: Anonymous

Chipar,

Try using:

(vla-saveas (vla-get-ActiveDocument (vlax-get-Acad-Object)) "C:\\Path\\Filename").

I find it a lot cleaner, particularly if you, the programmer, know where the file is to be saved to. You could extend it by getting the file name and path and STRCATing them together.

S
Message 4 of 13
Anonymous
in reply to: Anonymous

[I can't help but wonder what that routine does for you that ordinary SAVEAS doesn't do, other than
tell you it's done, but can't you tell when you get the Command: prompt back?]

Devitg's forces the filepath of the current drawing, and assumes you've already got a file name,
which it doesn't look like you would necessarily want.

You can replace the "~" [that's what's bringing up the dialog box] with "yourfilepathandname" if you
also have the name already figured out.

Or if you want to pre-determine the path only, and let the user put in the name in a dialog box,
replace the "~" with

(getfiled "Enter Drawing Name to Save to: " "yourfilepath" "dwg" 0)

That will open up a file dialog box already set to the path you program in there, so the user
doesn't have to navigate.

Read up about (getfiled) for the options.

--
Kent Cooper


wrote...
I found this "saveas" routine online @ http://forums.augi.com/showthread.php?t=50250

(DEFUN c:sas ()
(COMMAND "_saveas" "" "~")
(PRINC "\nSaveAs Complete:")
(PRINC)
) ;_ end of DEFUN

This routine pops up the saveas dialogue box. Does anybody know a way where I can specify the saveas
path in the routine?
Message 5 of 13
Anonymous
in reply to: Anonymous

thanks for you reply,
But "dwgprefix" is a readonly variable, what if I don't have the current file in the folder I want to save it as.
Also please tell me where should I use ur routine, add it to my routine or it is just by itself?
Message 6 of 13
Anonymous
in reply to: Anonymous

thanks kent,
looks like ur solution will work for me, will let u know if any probs. But thanks again for helping me out.
Message 7 of 13
Anonymous
in reply to: Anonymous

hey kent,
it worked, I tried this before but was using "\" to define the directory path and it didn't work,
but I tried it with "/" and it worked.
thanks a lot again
Message 8 of 13
Anonymous
in reply to: Anonymous

My pleasure. The (getfiled) function can also be used for commands like Insert, which is where I
first got to know it. I have a little Insert-from-the-Library menu item that calls up the Insert
command and uses (getfiled) to go straight to our symbol library folder, so the user doesn't have to
know where that is, or take the time to navigate to it.
--
Kent Cooper

wrote...
thanks kent,
looks like ur solution will work for me, will let u know if any probs. But thanks again for helping
me out.
Message 9 of 13
Anonymous
in reply to: Anonymous

You can use either / or \\ for those filepath dividers. More than one way to skin a cat....
--
Kent Cooper

wrote...
hey kent,
it worked, I tried this before but was using "\" to define the directory path and it didn't work,
but I tried it with "/" and it worked.
thanks a lot again
Message 10 of 13
scottividal
in reply to: Anonymous

Hi everyone,

I ´m tryng to do a app for saveas diferents files. 
I used this command

(command "SAVEAS" "LT2004" FILENAME_NEW)

where FILENAME_NEW is the new name.

But when I used this command the result is NIL.


there is any idea abot the fail?

ASV
Message 11 of 13
Kent1Cooper
in reply to: scottividal


@scottividal wrote:

.... when I used this command the result is NIL. ....

The (command) function always returns nil [read about it in the AutoLisp Functions Reference].  That doesn't mean it didn't work.

Kent Cooper, AIA
Message 12 of 13
Sea-Haven
in reply to: Anonymous

Be careful using "/" in directory names in some situations a space in the directory or file name will cause an error. Far safer using "\\". The space is detected as end of name. "C:/acadtemp/my lisps/lisp1.lsp" the blue is dropped.

Message 13 of 13
scottividal
in reply to: Sea-Haven

Hi again,

 

There arent any problem with \ beacasue I obtain the filepath.
I didn´t know that always print "NIL", thanks.

 

I write my code, for any review:

 

(defun c:SaveAs()


(setq FILENAME_OLD (getvar "dwgname"))
(setq FILEPATH (getvar "dwgprefix"))

(setq TEXT1 (vl-string-right-trim "HELLO.dwg" FILENAME_OLD))
(setq TEXT2 "WORLD")
(setq FILENAME_NEW (strcat TEXT1 TEXT2))

(command "_.SAVEAS" "LT2004" FILENAME_NEW)



(setq FILENAME_OLD NIL )
(setq FILEPATH NIL )
(setq TEXT1 NIL )
(setq TEXT2 NIL )
(setq FILENAME_NEW NIL )
)
ASV

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report