Create new file, with more text

Create new file, with more text

lmnDCJSJ
Enthusiast Enthusiast
1,116 Views
5 Replies
Message 1 of 6

Create new file, with more text

lmnDCJSJ
Enthusiast
Enthusiast

I want to make a lisp that crates a new file, based on the current file i am working with.
I want to add "_FINAL" to the filename.

 

i have this at the moment, but i dont get the "_FINAL" added

 

(defun c:Finalcreate()
setq fPath (getvar 'dwgprefix)
setq fName (getvar 'dwgname)
(command "saveas" "2010" (strcat fPath fName "_FINAL"))
(command "qsave")
(princ)
)

 

Best would be if it automatic owerwrate the file, if it exists.

AND if the file, currently in use has "__" 2 x underscore , all after the "__" should be erased before adding _FINAL to the filename.

 

I am currently doing this manually, and it is taking SO much time 😞

0 Likes
Accepted solutions (1)
1,117 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@lmnDCJSJ

 

for the first part of your question:

 

the result of saving with SAVEAS command would make that file current and than you QSAVE the file again which is redundant. so i suggest to change it to use SAVE command (instead of SAVEAS) but this won't let you to specify the dwg format so do it in OPTIONS.

 

the expert=5 sysvar is to tell autocad to skip alerting of existing file.

if the file in question is already open? that's another 'story' to VisualLISP\ActiveX to be solve.

 

moshe

 

 

(defun c:Finalcreate()
 (setq fPath (getvar 'dwgprefix))
 (setq fName (getvar 'dwgname))

 (setvar 'expert 5)
 (command "save" (strcat fPath fName "_FINAL"))
 (command "qsave")
 (setvar 'expert 0)
 (princ)
)

 

0 Likes
Message 3 of 6

dbhunia
Advisor
Advisor

this code will replace also

 

(defun c:Finalcreate()
(setq fPath (getvar 'dwgprefix))
(setq fName (getvar 'dwgname))
(setq fsl (strlen fName))
(setq fsl (- fsl 4))
(setq file (strcat fPath fName "_FINAL.dwg"))
(if (findfile file)
(vl-file-delete file)
)
(command "saveas" "2010" (strcat fPath fName "_FINAL"))
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 6

lmnDCJSJ
Enthusiast
Enthusiast

@Moshe-A

Thanks it works, but the filename has the .dwg embedded in the new filename.

eg: file1.dwg becomes file1.dwg_FINAL.dwg

Can i somehow use substr to remove the LAST 4 (.dwg)?

0 Likes
Message 5 of 6

dbhunia
Advisor
Advisor
Accepted solution

@lmnDCJSJ wrote:

I want to make a lisp that crates a new file, based on the current file i am working with.
I want to add "_FINAL" to the filename.

 

i have this at the moment, but i dont get the "_FINAL" added

 

(defun c:Finalcreate()
setq fPath (getvar 'dwgprefix)
setq fName (getvar 'dwgname)
(command "saveas" "2010" (strcat fPath fName "_FINAL"))
(command "qsave")
(princ)
)

 

Best would be if it automatic owerwrate the file, if it exists.

AND if the file, currently in use has "__" 2 x underscore , all after the "__" should be erased before adding _FINAL to the filename.

 

I am currently doing this manually, and it is taking SO much time 😞


Try this ...

 

(defun c:Finalcreate()
(setq fPath (getvar 'dwgprefix))
(setq fName (getvar 'dwgname))
(while
(wcmatch fName "*_*")
(setq fName (vl-string-subst "" "_" fName))
)
(setq fsl (strlen fName))
(setq fsl (- fsl 4))
(setq Fname (substr fName 1 fsl))
(setq file (strcat fPath fName "_FINAL.dwg"))
(if (findfile file)
(vl-file-delete file)
)
(command "saveas" "2010" (strcat fPath fName "_FINAL"))
(princ)
)


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 6

lmnDCJSJ
Enthusiast
Enthusiast

@dbhunia

Works like i wanted 🙂 thanks.

0 Likes