rcb007 Posted August 22, 2022 Posted August 22, 2022 (edited) I have the following code that seems to error out when a file already exists. It is part of an on going lisp. Do this, then save, do this, then save. etc... However, When the file name exists, and I try to overwrite the file, it stops the continuation of the routine. the only way I know how to get it to work, is to delete the existing file before starting the routine. (command "_.saveas" "" (getfiled "Saveas:" (strcat (getvar 'dwgprefix) "FileName") "dwg" 1)) Command: Yes or No, please. ; error: Function cancelled A drawing with this name already exists. Do you want to replace it? <N> Y I did lookup the following code, but am unsure how to tie this together. (if (findfile (strcat filename ".dwg")) (command "_.save" filename "_y");;replaces the existing file (command "_.save" filename)(Alert "Did not Save over existing file.") ;;does not replace the existing file ) If there is a better idea, I hope you dont mind to share. Thank you Edited August 22, 2022 by rcb007 Quote
marko_ribar Posted August 22, 2022 Posted August 22, 2022 There should be no problem IMHO with vla-xxx functions... (vla-saveas (vla-get-activedocument (vlax-get-acad-object)) (strcat (getvar 'dwgprefix) (if (getvar 'dwgtitled) (getvar 'dwgname) "Drawingname"))) Though untested... 1 Quote
Steven P Posted August 22, 2022 Posted August 22, 2022 If I am overwriting text files I will often delete them first, however if the routine crashes in between the delete and create it all goes wrong.... Keep the delete and create close to each other in the progam Modifying your idea above, split the saveas part from the get file name part, then test the filename if it exists, something like this (setq MyFileName (getfiled "Saveas:" (strcat (getvar 'dwgprefix) "FileName") "dwg" 1)) (if (findfile (strcat MyFileNAme ".dwg")) (progn ;filename exsits (command "_.save" filename "_y") (princ (strcat MyFileName " was over written")) ) ; end progn (progn ; Filename doesn't exist (command "_.save" filename) (princ "A new file was created.") ;;does not replace the existing file ) ; end progn ) 1 Quote
ronjonp Posted August 22, 2022 Posted August 22, 2022 @rcb007 You could also set EXPERT to 2 or higher before saving to suppress the prompt. 1 Quote
rcb007 Posted August 23, 2022 Author Posted August 23, 2022 16 hours ago, ronjonp said: @rcb007 You could also set EXPERT to 2 or higher before saving to suppress the prompt. I think you hit it on the head... Seems likes its working as it should. Thank you for pointing that out. @Steven P, that is an interesting way. Not bad. 1 Quote
tombu Posted August 23, 2022 Posted August 23, 2022 On 8/22/2022 at 10:39 AM, marko_ribar said: There should be no problem IMHO with vla-xxx functions... (vla-saveas (vla-get-activedocument (vlax-get-acad-object)) (strcat (getvar 'dwgprefix) (if (getvar 'dwgtitled) (getvar 'dwgname) "Drawingname"))) Though untested... Tested and worked perfectly. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.