File dialog (for new OR existing file)?

File dialog (for new OR existing file)?

doni49
Mentor Mentor
219 Views
4 Replies
Message 1 of 5

File dialog (for new OR existing file)?

doni49
Mentor
Mentor

I've used the GETFILED function in the past to select an existing file or to create a new one.  But is there a way to prompt for a filename:

  1. if the chosen file DOES NOT EXIST, return the filename but indicate it doesn't exist yet;
  2. if the chosen file DOES EXIST, ask the user if they want to overwrite it, append it or choose a different file;

and then the lisp routine will continue to process the file based on the information provided?

 

I'm working on a lisp routine to export a linetype.  I want the user to select a filename.  If the file does not exist, a new file will be generated.  If the file does exist, I want the user to choose between overwriting it or appending it OR CHOOSING  a different file.

 

I don't see a way to do this but I'm hoping someone has found a way.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
220 Views
4 Replies
Replies (4)
Message 2 of 5

paullimapa
Mentor
Mentor

Well you won't be able to choose a file if it doesn't exist so your first option is not possible

Now if you use getfiled with flag 1 then any existing file you select you'll be prompted with a warning to overwrite:

(getfiled "Select a Script File" (getvar "dwgprefix") "scr" 1)

paullimapa_0-1747762232264.png

Unfortunately, if you were to type in a filename that doesn't exist then there would be no warning.

You can read up on the other flags here:

https://help.autodesk.com/view/ACD/2026/ENU/?guid=GUID-AD65DF88-5218-4655-B877-B4D33B9FB6D1


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

doni49
Mentor
Mentor

@paullimapa wrote:

Well you won't be able to choose a file if it doesn't exist so your first option is not possible

Now if you use getfiled with flag 1 then any existing file you select you'll be prompted with a warning to overwrite:

(getfiled "Select a Script File" (getvar "dwgprefix") "scr" 1)

paullimapa_0-1747762232264.png

Unfortunately, if you were to type in a filename that doesn't exist then there would be no warning.

You can read up on the other flags here:

https://help.autodesk.com/view/ACD/2026/ENU/?guid=GUID-AD65DF88-5218-4655-B877-B4D33B9FB6D1


Ok.  Thanks.  As far as the first option, I was hoping that instead of "selecting" an existing file, it would recognize that I wanted create a NEW file.  But I was already guessing it wasn't possible -- I thought maybe someone had found a way.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 4 of 5

paullimapa
Mentor
Mentor

Also after the filename is returned, you should also check if the file actually exists with the findfile function.

If it does, then your code should include options to handle overwrite vs append.


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

Sea-Haven
Mentor
Mentor

Using (setq files (vl-directory-files dir-name "*.lin" 0)) will return a list of lin files in a directory, so can put all the names into a dcl list box pick one or click say Cancel, by selecting cancel you imply I want to add a new one.

 

If that sounds useful can provide  code, plenty of examples out there about using a list box, hint Lee-mac.com.

0 Likes