How's this?
(defun C:SAVE_AS_SITE()
(setq oldcmddia (getvar "cmddia"))
(setvar "cmddia" 0)
(setq new_dwg_name (getvar "dwgname") )
(while (< (strlen new_dwg_name) 7)
(setq new_dwg_name (strcat "0" new_dwg_name))
)
(setq new_dwg_name (substr new_dwg_name 1 3))
(setq new_dwg_name (strcat (getvar "dwgprefix") new_dwg_name "-site.dwg"))
(if (findfile new_dwg_name)
(progn
(princ (strcat "\nFile " new_dwg_name " already exists. "))
(initget "Yes No")
(if (= "Yes" (getkword "\nOverwrite? Yes, <No>: "))
(progn
(command "-wblock" new_dwg_name "y" "*")
(while (= 1 (getvar "cmdactive"))
(command "n")
)
)
(princ "\nCancelled. ")
)
)
(progn
(command "-wblock" new_dwg_name "*")
(while (= 1 (getvar "cmdactive"))
(command "n")
)
)
)
(setvar "cmddia" oldcmddia)
(prin1)
)
The reason I temporarily reset the system variable "cmddia" to 0 is because if you have AutoCAD Map it will pop up a dialog box asking
Include Autodesk Map information in the export?
and AutoLISP can't click the buttons on that dialog box. Whereas if cmddia is set to 0, rather than getting a dialog box you get another prompt at the AutoCAD command line, and AutoLISP can respond to that prompt.
Now look at a couple more system variables, dwgprefix and dwgname. If your drawing is named
I:\PROJECT\SUR\15005600SS\DWG\WKS2017,DWG
then the dwgname system variable is
WKS2017.DWG
and the dwgprefix system variable is
I:\PROJECT\SUR\15005600SS\DWG\
You want the first three characters of the name of your current drawing for the prefix for the output file. The first thing that comes to mind is to just use
(substr (getvar "dwgname") 1 3)
But suppose the name of your drawing has only one or two characters, e.g. SP.DWG or A.DWG? That's what the first while loop does; it adds the character "0" (that's a zero, not a capital "oh") to the beginning of new_dwg_name until it is at least seven characters long, including the ".dwg" part. So if your drawing was named SP.DWG then NEW_DWG_NAME becomes
0SP.dwg
and if your drawing was named A.DWG then NEW_DWG_NAME becomes
00A.dwg
Now that the part before the period is at least three characters long, chop it down to the first three characters with
(setq new_dwg_name (substr new_dwg_name 1 3))
Now build the output file name. Add together the path of the original drawing, the three letter prefix stored as NEW_DWG_NAME, and the string "-SITE.DWG". If the original drawing was
I:\PROJECT\SUR\15005600SS\DWG\WKS2017,DWG
then (setq new_dwg_name (strcat (getvar "dwgprefix") new_dwg_name "-site.dwg")) returns
I:\PROJECT\SUR\15005600SS\DWG\WKS-site.dwg
Next, use the (findfile) function to see if there's already a file by that name. If there is, then this program asks you if you want the -WBLOCK command to overwrite it, and if you say "yes" then it runs the -WBLOCK command, with the following prompts:
Command: -WBLOCK
Enter name of output file: i:\project\sur\15005600ss\dwg\wks-site.dwg
I:\project\sur\15005600ss\dwg\wks-site.dwg already exists, do you want to replace it? [Yes/No] <N>: y
Enter name of existing block or [= (block=output file)/* (whole drawing)] <define new drawing>: *
But if the there's not already a file with the name stored in new_dwg_name it runs the -wblock command without that second prompt:
Command: -WBLOCK
Enter name of output file: i:\project\sur\15005600ss\dwg\wks-site.dwg
Enter name of existing block or [= (block=output file)/* (whole drawing)] <define new drawing>: *
Now there's another while loop. What's happening there is that if you are running AutoCAD Map you will get that "Include Autodesk Map information in the export?" prompt at the command line, to which you want to answer "No". Since you're still in the middle of the -WBLOCK command the system variable cmdactive will be 1, and the loop will issue an "n" to the command line. This will complete the -WBLOCK command, at which point cmdactive will be 0 and you'll jump out of the loop. If, however, you aren't running AutoCAD Map, the -WBLOCK command will have already terminated, cmdactive will be 0, and the loop will be bypassed.
Finally, reset the cmddia system variable to its original values and exit.
It's possible that -WBLOCK will have failed, however. If you don't have write permission in the target directory, or the disc is full, or if you are trying to overwrite a read-only file, then you'll see
Error writing/closing file.
at the command line.