add line to script on last drawing in list only?

add line to script on last drawing in list only?

DC-MWA
Collaborator Collaborator
948 Views
4 Replies
Message 1 of 5

add line to script on last drawing in list only?

DC-MWA
Collaborator
Collaborator

Hi all,

I have a little routine we use at the end of projects. It tidy's up the drawing files.

It creates a script file to process all the drawings in a selected folder.

I would like to add an additional line to the script but only on the last drawing in the list to be processed.

I want to run (dos_delete (strcat (getvar "DWGPREFIX") "*.bak")) on the last drawing in the script and not the other drawings.

I have attached the lisp.

Thanks!

-dc

0 Likes
Accepted solutions (1)
949 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

Try this

 

)
(close scriptname)
)

)
(setq endline (strcat (getvar 'DWGPREFIX) "*.bak")) (write-line endline filexxx ) (close scriptname) )

 

 

0 Likes
Message 3 of 5

SeeMSixty7
Advisor
Advisor
Accepted solution

If that is what you want to do, then create a variable to hold the length of th elist, then when you are at the end of the list write the statement out.

 

See here:

(defun C:TidyUp ( / FCTN count dir filename scrname scriptname)
(alert "TidyUp will open, purge all, audit and zoom extents drawings.\n\nUser MUST EXIT all drawings to be processed")
(initget "Yes No")
(setq FCTN (getkword "\nThis program will \"Tidy Up\" all drawings in the selected directory. Proceed? [Yes/No] <Yes>: "))
(if (= FCTN nil) (setq FCTN "Yes"))
(if (= FCTN "Yes")
(progn

(if (setq dir (getfiled "Select the drawing directory:" "f:/" "dwg" 16))
(setq dir (vl-filename-directory dir))
)
(if dir
(setq files (vl-directory-files dir "*.dwg" 1))
)
(if files
(progn
;(setq scrname (strcat "f:\\TidyUp-" (getvar "loginname") ".scr"));name script file per user

(setq scrname (strcat dir "\\TidyUp-" (getvar "loginname") ".scr"));name script file per project
(setq scriptname (open scrname "w");open to write script file
count 0
)
(setq len (length files)) ;;;;;ADDED THIS FOR THE LENGTH OF THE LIST OF FILES
(while (setq filename (nth count files))
(setq filename (strcat dir "\\" filename))
(write-line (strcat "_open \"" filename "\"") scriptname)
(write-line "_purge all * no" scriptname)
(write-line "_purge all * no" scriptname)
(write-line "_audit yes" scriptname)
(write-line "_zoom extents" scriptname)
(write-line "_qsave" scriptname)
(if (= (1+ count) len) ;;;;CHECK TO SEE IF ITs the LAST FILE
	(write-line "(dos_delete (strcat (getvar \"DWGPREFIX\") \"*.bak\"))" scriptname)
)
(write-line "_close" scriptname)
(setq count (1+ count))
)

(close scriptname)
)
)
(command "script" scrname);run script file created
(princ)
);pr
);if

(if (= FCTN "No")
(progn
(Princ "\nNo action performed.")
);pr
);if
(princ)
)

Good luck,

0 Likes
Message 4 of 5

DC-MWA
Collaborator
Collaborator

This worked great. I was able to run another lisp to at the last drawing to perform final tasks as well.

Awesome!

Thank you very much!!

Message 5 of 5

SeeMSixty7
Advisor
Advisor

You bet! Glad it worked out.

0 Likes