Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Batch routine crashes after a dozen drawings?

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
288 Views, 7 Replies

Batch routine crashes after a dozen drawings?

I have a lisp routine which creates a script file that runs thru an entire
directory of drawing files. For some reason the script continuously crashes
around the 12th drawing opened. I changed to single drawing mode, so only
one drawing is open at a time, so memory shouldn't be an issue.

Can anyone figure out why this script crashes?

Thanks for your help.

Lisp is below:

;********************** Batch sub-routine
***************************************
; Hardcode the tasks required for each individual drawing.
(defun c:do_batch ()
(command "model")
(command "-layer" "s" "0" "")
(command "-xref" "attach" "K:\\projects\\101-041\\DWG\\REF\\Wetlands.dwg"
"0,0" "1" "" "")
(command "xclip" pause)
(COMMAND "QSAVE")
)
;********************** Main-function
*******************************************
(defun c:batch (/ dirp lst1 llst1 llp fil1 img img1)
(save_vars)
(setq plot_ans nil layer_ans nil purge_ans nil )

;*** if multiple drawings open ends program
(if (= (vla-get-count (vla-get-documents (vlax-get-acad-object))) 1)
(progn
(command "sdi" "1")
(command "qsave")

;*** getting path
(setq dirp (getvar "dwgprefix"))

;*** list all files in folder of certain type
(setq lst1 (vl-directory-files dirp "*.dwg"))

;*** defining amount of files in list
(setq llst1 (- (length lst1) 1))

;*** setting list value to zero
(setq llp 0)

;*** opening script file
(setq fil1 (open (strcat dirp "trash.scr") "w"))

;*** Open Dialog box at command line
(write-line "filedia" fil1)
(write-line "0" fil1)

;*** create loop that will write file
(while (<= llp llst1)

;*** gets drawing name
(setq img (nth llp lst1))

;*** sets drawing name with path
(setq img1 (strcat dirp img))

;*** Write open and filename to script file
(write-line "open" fil1)
(write-line (strcat "\"" img1 "\"") fil1)
;*** don't modify anything above

;*** Add sub-function here, all hardcoding should be done in
sub-function
(write-line "do_batch" fil1)

;*** don't modify this
(write-line "qsave" fil1)
(setq llp (+ llp 1))
)

;*** Reverts dialog box to screen, resets SDI=0, saves the file
(write-line "filedia" fil1)
(write-line "1" fil1)
(write-line "sdi" fil1)
(write-line "0" fil1)
(write-line "qsave" fil1)
(close fil1) ;;; close file

;*** automatically runs the script routine
(command "script" "trash.scr")
) ; end progn
(progn
(alert "\nOnly one drawing can be open to run this routine")
(alert "\nClose other drawings and re-run program")
) ; end progn
) ; end if
(restore_vars)
)
7 REPLIES 7
Message 2 of 8
BillZ
in reply to: Anonymous

Are you checking for drawings that may be open by another user? Or for drawings that are write protected? I have had trouble with scripts this way.

Bill
Message 3 of 8
Anonymous
in reply to: Anonymous

I copied the drawings to a new folder and ran the lisp from
there, so no drawings are open or write protected.

 

When the script crashes, I open the script in a text editor
and remove the processed drawings and re-run the script which works fine on the
first 12 or so drawings (including the one it previously crashed on). This cycle
repeats continuously repeats itself, always crashing on the 12 or so
drawing.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Are
you checking for drawings that may be open by another user? Or for drawings
that are write protected? I have had trouble with scripts this way.

Bill

Message 4 of 8
Anonymous
in reply to: Anonymous

Memory is an issue. AutoCAD does not release all of the menory it uses
while a drawing is open, and the system will eventually run out of
resources. Twelve drawings is a little short though, unless you don't have a
lot of RAM to begin with or the drawings are very large.

I use a lisp routine for this so that I can stop it when the system slows
down, and restart where I left off without having to modify the script. The
drawing list is stored in a file and updated with each open. The script only
deals with the next file in the list.

"Joseph Christou" wrote in message
news:537455C3CE18D761ACA5116D09C01294@in.WebX.maYIadrTaRb...
> I have a lisp routine which creates a script file that runs thru an entire
> directory of drawing files. For some reason the script continuously
crashes
> around the 12th drawing opened. I changed to single drawing mode, so only
> one drawing is open at a time, so memory shouldn't be an issue.
>
> Can anyone figure out why this script crashes?
>
> Thanks for your help.
>
> Lisp is below:
>
> ;********************** Batch sub-routine
> ***************************************
> ; Hardcode the tasks required for each individual drawing.
> (defun c:do_batch ()
> (command "model")
> (command "-layer" "s" "0" "")
> (command "-xref" "attach"
"K:\\projects\\101-041\\DWG\\REF\\Wetlands.dwg"
> "0,0" "1" "" "")
> (command "xclip" pause)
> (COMMAND "QSAVE")
> )
> ;********************** Main-function
> *******************************************
> (defun c:batch (/ dirp lst1 llst1 llp fil1 img img1)
> (save_vars)
> (setq plot_ans nil layer_ans nil purge_ans nil )
>
> ;*** if multiple drawings open ends program
> (if (= (vla-get-count (vla-get-documents (vlax-get-acad-object))) 1)
> (progn
> (command "sdi" "1")
> (command "qsave")
>
> ;*** getting path
> (setq dirp (getvar "dwgprefix"))
>
> ;*** list all files in folder of certain type
> (setq lst1 (vl-directory-files dirp "*.dwg"))
>
> ;*** defining amount of files in list
> (setq llst1 (- (length lst1) 1))
>
> ;*** setting list value to zero
> (setq llp 0)
>
> ;*** opening script file
> (setq fil1 (open (strcat dirp "trash.scr") "w"))
>
> ;*** Open Dialog box at command line
> (write-line "filedia" fil1)
> (write-line "0" fil1)
>
> ;*** create loop that will write file
> (while (<= llp llst1)
>
> ;*** gets drawing name
> (setq img (nth llp lst1))
>
> ;*** sets drawing name with path
> (setq img1 (strcat dirp img))
>
> ;*** Write open and filename to script file
> (write-line "open" fil1)
> (write-line (strcat "\"" img1 "\"") fil1)
> ;*** don't modify anything above
>
> ;*** Add sub-function here, all hardcoding should be done in
> sub-function
> (write-line "do_batch" fil1)
>
> ;*** don't modify this
> (write-line "qsave" fil1)
> (setq llp (+ llp 1))
> )
>
> ;*** Reverts dialog box to screen, resets SDI=0, saves the file
> (write-line "filedia" fil1)
> (write-line "1" fil1)
> (write-line "sdi" fil1)
> (write-line "0" fil1)
> (write-line "qsave" fil1)
> (close fil1) ;;; close file
>
> ;*** automatically runs the script routine
> (command "script" "trash.scr")
> ) ; end progn
> (progn
> (alert "\nOnly one drawing can be open to run this routine")
> (alert "\nClose other drawings and re-run program")
> ) ; end progn
> ) ; end if
> (restore_vars)
> )
>
>
Message 5 of 8
Anonymous
in reply to: Anonymous

I have a similar program that does what you are trying to do. I have not
had any problems processing multiple drawing files. Mine differs from yours
in a few ways:

My program does not call a lisp file, but rather writes all of the plotting
information out to the script file in the form of a lisp coomand structure
ie: (command "plot" etc...)

I don't save the drawing files after plotting them.

I'm not sure if these changes will help, but I know it works if you run it
this way...

Steve Watts


"Joseph Christou" wrote in message
news:537455C3CE18D761ACA5116D09C01294@in.WebX.maYIadrTaRb...
> I have a lisp routine which creates a script file that runs thru an entire
> directory of drawing files. For some reason the script continuously
crashes
> around the 12th drawing opened. I changed to single drawing mode, so only
> one drawing is open at a time, so memory shouldn't be an issue.
>
> Can anyone figure out why this script crashes?
>
> Thanks for your help.
>
> Lisp is below:
>
> ;********************** Batch sub-routine
> ***************************************
> ; Hardcode the tasks required for each individual drawing.
> (defun c:do_batch ()
> (command "model")
> (command "-layer" "s" "0" "")
> (command "-xref" "attach"
"K:\\projects\\101-041\\DWG\\REF\\Wetlands.dwg"
> "0,0" "1" "" "")
> (command "xclip" pause)
> (COMMAND "QSAVE")
> )
> ;********************** Main-function
> *******************************************
> (defun c:batch (/ dirp lst1 llst1 llp fil1 img img1)
> (save_vars)
> (setq plot_ans nil layer_ans nil purge_ans nil )
>
> ;*** if multiple drawings open ends program
> (if (= (vla-get-count (vla-get-documents (vlax-get-acad-object))) 1)
> (progn
> (command "sdi" "1")
> (command "qsave")
>
> ;*** getting path
> (setq dirp (getvar "dwgprefix"))
>
> ;*** list all files in folder of certain type
> (setq lst1 (vl-directory-files dirp "*.dwg"))
>
> ;*** defining amount of files in list
> (setq llst1 (- (length lst1) 1))
>
> ;*** setting list value to zero
> (setq llp 0)
>
> ;*** opening script file
> (setq fil1 (open (strcat dirp "trash.scr") "w"))
>
> ;*** Open Dialog box at command line
> (write-line "filedia" fil1)
> (write-line "0" fil1)
>
> ;*** create loop that will write file
> (while (<= llp llst1)
>
> ;*** gets drawing name
> (setq img (nth llp lst1))
>
> ;*** sets drawing name with path
> (setq img1 (strcat dirp img))
>
> ;*** Write open and filename to script file
> (write-line "open" fil1)
> (write-line (strcat "\"" img1 "\"") fil1)
> ;*** don't modify anything above
>
> ;*** Add sub-function here, all hardcoding should be done in
> sub-function
> (write-line "do_batch" fil1)
>
> ;*** don't modify this
> (write-line "qsave" fil1)
> (setq llp (+ llp 1))
> )
>
> ;*** Reverts dialog box to screen, resets SDI=0, saves the file
> (write-line "filedia" fil1)
> (write-line "1" fil1)
> (write-line "sdi" fil1)
> (write-line "0" fil1)
> (write-line "qsave" fil1)
> (close fil1) ;;; close file
>
> ;*** automatically runs the script routine
> (command "script" "trash.scr")
> ) ; end progn
> (progn
> (alert "\nOnly one drawing can be open to run this routine")
> (alert "\nClose other drawings and re-run program")
> ) ; end progn
> ) ; end if
> (restore_vars)
> )
>
>
Message 6 of 8
Anonymous
in reply to: Anonymous

Have you explicitly saved and closed each file as they're being processed?
I know that you said you set SDI mode. In a couple of batch-script routines
I've written, to convert the routines from R14 to R2000 with MDI, I
reprogrammed them to open each drawing, do something to tyhe drawing, then
save and close the file, then move onto the next DWG. Before doing that, It
would always crash on about the 16-18th file it opened (out of memory).

Also, consider running an audit on the file near or at the point of
crashing... maybe the file is corrupted and needs repair.

--
Mark McDonough
Sasaki Associates
http://www.sasaki.com

"Joseph Christou" wrote in message
news:537455C3CE18D761ACA5116D09C01294@in.WebX.maYIadrTaRb...
> I have a lisp routine which creates a script file that runs thru an entire
> directory of drawing files. For some reason the script continuously
crashes
> around the 12th drawing opened. I changed to single drawing mode, so only
> one drawing is open at a time, so memory shouldn't be an issue.
>
> Can anyone figure out why this script crashes?
>
> Thanks for your help.
>
> Lisp is below:
>
> ;********************** Batch sub-routine
> ***************************************
> ; Hardcode the tasks required for each individual drawing.
> (defun c:do_batch ()
> (command "model")
> (command "-layer" "s" "0" "")
> (command "-xref" "attach"
"K:\\projects\\101-041\\DWG\\REF\\Wetlands.dwg"
> "0,0" "1" "" "")
> (command "xclip" pause)
> (COMMAND "QSAVE")
> )
> ;********************** Main-function
> *******************************************
> (defun c:batch (/ dirp lst1 llst1 llp fil1 img img1)
> (save_vars)
> (setq plot_ans nil layer_ans nil purge_ans nil )
>
> ;*** if multiple drawings open ends program
> (if (= (vla-get-count (vla-get-documents (vlax-get-acad-object))) 1)
> (progn
> (command "sdi" "1")
> (command "qsave")
>
> ;*** getting path
> (setq dirp (getvar "dwgprefix"))
>
> ;*** list all files in folder of certain type
> (setq lst1 (vl-directory-files dirp "*.dwg"))
>
> ;*** defining amount of files in list
> (setq llst1 (- (length lst1) 1))
>
> ;*** setting list value to zero
> (setq llp 0)
>
> ;*** opening script file
> (setq fil1 (open (strcat dirp "trash.scr") "w"))
>
> ;*** Open Dialog box at command line
> (write-line "filedia" fil1)
> (write-line "0" fil1)
>
> ;*** create loop that will write file
> (while (<= llp llst1)
>
> ;*** gets drawing name
> (setq img (nth llp lst1))
>
> ;*** sets drawing name with path
> (setq img1 (strcat dirp img))
>
> ;*** Write open and filename to script file
> (write-line "open" fil1)
> (write-line (strcat "\"" img1 "\"") fil1)
> ;*** don't modify anything above
>
> ;*** Add sub-function here, all hardcoding should be done in
> sub-function
> (write-line "do_batch" fil1)
>
> ;*** don't modify this
> (write-line "qsave" fil1)
> (setq llp (+ llp 1))
> )
>
> ;*** Reverts dialog box to screen, resets SDI=0, saves the file
> (write-line "filedia" fil1)
> (write-line "1" fil1)
> (write-line "sdi" fil1)
> (write-line "0" fil1)
> (write-line "qsave" fil1)
> (close fil1) ;;; close file
>
> ;*** automatically runs the script routine
> (command "script" "trash.scr")
> ) ; end progn
> (progn
> (alert "\nOnly one drawing can be open to run this routine")
> (alert "\nClose other drawings and re-run program")
> ) ; end progn
> ) ; end if
> (restore_vars)
> )
>
>
Message 7 of 8
Anonymous
in reply to: Anonymous

Have you explored running your script file using the SCRIPTPRO free
migration tool?

--
Dean Saadallah
http://www.pendean.com
LT Express utilities
http://www.pendean.com/ltexpress
Expanded Links Pages
http://www.pendean.com/lt/links.htm
--

"Joseph Christou" wrote in message
news:EFF05FB89E50C7F2EBEDC3832A4F9132@in.WebX.maYIadrTaRb...
> I copied the drawings to a new folder and ran the lisp from there, so no
drawings are open or write protected.
>
> When the script crashes, I open the script in a text editor and remove the
processed drawings and re-run the script which works fine on the first 12 or
so drawings (including the one it previously crashed on). This cycle repeats
continuously repeats itself, always crashing on the 12 or so drawing.
> "BillZ" wrote in message
news:f12d696.0@WebX.maYIadrTaRb...
> Are you checking for drawings that may be open by another user? Or for
drawings that are write protected? I have had trouble with scripts this way.
> Bill
>
Message 8 of 8
Anonymous
in reply to: Anonymous

Thanks for all the suggestions, tried most of them with no luck,

However defragmenting my hard drive seemed to be the solution. My drive had
almost 30 GB of available space on a 40 GB hard drive, but somehow my lisp
now works perfectly after the defragmenting.

Just thought you would like to know.

The more I know about computers, the more I find out I don't know about
computers. 🙂



"Mark McDonough" wrote in message
news:4D75C89B5ACB76B3F530E01C1D85DE7C@in.WebX.maYIadrTaRb...
> Have you explicitly saved and closed each file as they're being processed?
> I know that you said you set SDI mode. In a couple of batch-script
routines
> I've written, to convert the routines from R14 to R2000 with MDI, I
> reprogrammed them to open each drawing, do something to tyhe drawing, then
> save and close the file, then move onto the next DWG. Before doing that,
It
> would always crash on about the 16-18th file it opened (out of memory).
>
> Also, consider running an audit on the file near or at the point of
> crashing... maybe the file is corrupted and needs repair.
>
> --
> Mark McDonough
> Sasaki Associates
> http://www.sasaki.com
>
> "Joseph Christou" wrote in message
> news:537455C3CE18D761ACA5116D09C01294@in.WebX.maYIadrTaRb...
> > I have a lisp routine which creates a script file that runs thru an
entire
> > directory of drawing files. For some reason the script continuously
> crashes
> > around the 12th drawing opened. I changed to single drawing mode, so
only
> > one drawing is open at a time, so memory shouldn't be an issue.
> >
> > Can anyone figure out why this script crashes?
> >
> > Thanks for your help.
> >
> > Lisp is below:
> >
> > ;********************** Batch sub-routine
> > ***************************************
> > ; Hardcode the tasks required for each individual drawing.
> > (defun c:do_batch ()
> > (command "model")
> > (command "-layer" "s" "0" "")
> > (command "-xref" "attach"
> "K:\\projects\\101-041\\DWG\\REF\\Wetlands.dwg"
> > "0,0" "1" "" "")
> > (command "xclip" pause)
> > (COMMAND "QSAVE")
> > )
> > ;********************** Main-function
> > *******************************************
> > (defun c:batch (/ dirp lst1 llst1 llp fil1 img img1)
> > (save_vars)
> > (setq plot_ans nil layer_ans nil purge_ans nil )
> >
> > ;*** if multiple drawings open ends program
> > (if (= (vla-get-count (vla-get-documents (vlax-get-acad-object))) 1)
> > (progn
> > (command "sdi" "1")
> > (command "qsave")
> >
> > ;*** getting path
> > (setq dirp (getvar "dwgprefix"))
> >
> > ;*** list all files in folder of certain type
> > (setq lst1 (vl-directory-files dirp "*.dwg"))
> >
> > ;*** defining amount of files in list
> > (setq llst1 (- (length lst1) 1))
> >
> > ;*** setting list value to zero
> > (setq llp 0)
> >
> > ;*** opening script file
> > (setq fil1 (open (strcat dirp "trash.scr") "w"))
> >
> > ;*** Open Dialog box at command line
> > (write-line "filedia" fil1)
> > (write-line "0" fil1)
> >
> > ;*** create loop that will write file
> > (while (<= llp llst1)
> >
> > ;*** gets drawing name
> > (setq img (nth llp lst1))
> >
> > ;*** sets drawing name with path
> > (setq img1 (strcat dirp img))
> >
> > ;*** Write open and filename to script file
> > (write-line "open" fil1)
> > (write-line (strcat "\"" img1 "\"") fil1)
> > ;*** don't modify anything above
> >
> > ;*** Add sub-function here, all hardcoding should be done in
> > sub-function
> > (write-line "do_batch" fil1)
> >
> > ;*** don't modify this
> > (write-line "qsave" fil1)
> > (setq llp (+ llp 1))
> > )
> >
> > ;*** Reverts dialog box to screen, resets SDI=0, saves the file
> > (write-line "filedia" fil1)
> > (write-line "1" fil1)
> > (write-line "sdi" fil1)
> > (write-line "0" fil1)
> > (write-line "qsave" fil1)
> > (close fil1) ;;; close file
> >
> > ;*** automatically runs the script routine
> > (command "script" "trash.scr")
> > ) ; end progn
> > (progn
> > (alert "\nOnly one drawing can be open to run this routine")
> > (alert "\nClose other drawings and re-run program")
> > ) ; end progn
> > ) ; end if
> > (restore_vars)
> > )
> >
> >
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost