Jump to content

if error resume


svorgodne

Recommended Posts

I have the problem I am running a variable script on dozens of files in one shot. And sometimes the script crashes when there is a false command input. So I am looking for a solution which can stop the process when a failure is found and continue with the next two and final commands so the process can continue until all files were done as you can see in the attached script.

open
"name_01.dwg"
LINE
0,0
100,100
(command)
qsave
close
open
"name_02.dwg"
LINE
0,0
100,100
(command)
qsave
close
open
"name_03.dwg"
LINE
0,0
100,100
(command)
qsave
close

 

I have tried

(command)

and it is not always working.

 

The code:

 

\U+001B

 

works beyond expectetions because it stops completely the process and cannot activate somehow the "resume"command.

 

Any ideas?

 

Thanks in advance

 

Sergio

Link to comment
Share on other sites

No, It is a simple script I run with the normal Script command from AutoCAD.

 

If it helps to know. I am writing all my programs in AutoLisp.

 

Thx

Link to comment
Share on other sites

That's just how Scripts work... They stop executing when an error is encountered.

 

If it helps to know. I am writing all my programs in AutoLisp.

 

Post your code?

Link to comment
Share on other sites

That's just how Scripts work... They stop executing when an error is encountered.

 

from experience I would say they don't stop, they just try to interpret each new line as the next typed input. Sometimes you're lucky with that result, sometimes you're unlucky. Either way you will probably wish it had just stopped.

Link to comment
Share on other sites

Greeting, Dave... It's been a while; hope all is well with you. :beer:

 

from experience I would say they don't stop, they just try to interpret each new line as the next typed input. Sometimes you're lucky with that result, sometimes you're unlucky. Either way you will probably wish it had just stopped.

I was speaking generally, of course... You are correct with the actual sequence of events, I was merely pointing out that the requested behavior of upon error, resuming in order to successfully complete the others actions on other Documents is not possible.

 

Especially given that the OP has identified that they've ported this task over to LISP, I didn't see the point in elaborating when making my earlier post.

 

Cheers

Link to comment
Share on other sites

Here it is the lisp. Like I said before, the routine from "stopping-resuming" the script is sometimes working and sometimes not

(setq files (list))
(setq command_list (list))
(defun fn_name_dwg
   ()
   (setq name_dwg
       (getfiled 
           "Select drawings to edit" 
           ""
           "dwg" 8
       )
   )
   (if
       (= (vl-string-search "\\" name_dwg) nil)
       (setq name_dwg (strcat (getvar 'dwgprefix) name_dwg))
   )    
)
(defun lst_files
   ()
   (fn_name_dwg)
   (setq files
       (append files
           (list
               name_dwg
           )
       )
   )
   (setq files (vl-sort files '<))
   (setq lst_ord (list))
   (foreach miembro files
       (if
           (not (member miembro lst_ord))
           (setq lst_ord (append lst_ord (list miembro)))
       )
   )
   (setq files lst_ord)
)
(defun cmmd
   ()
   (textscr)
   (princ
       "\nEnter valid commands to process drawings\n\n"
   )
   (while (/= commands (strcase "END"))
       (setq commands (strcase (getstring t "type \"END\" when ur done - ")))
       (setq command_list (append command_list (list commands)))
   )
   (setq commands nil)
   (setq cnt (length command_list))    
   (setq command_list (vl-remove (nth (- cnt 1) command_list) command_list))
)
(defun run
   ()
   (setq command_list (append (list "(defun stop () (command) (command \"resume\"))") command_list))
   (setq command_list (cons "open" command_list))
   (setq command_list
       (append command_list 
           (list "(stop)" "qsave" "close")
       )
   )
   (setq write_name (strcat (getenv "tmp") "\\" "run_script.scr"))
   (setq write_scr (open write_name "w"))
   (setq cnt_1 1)
   (setq cnt_cmd (length command_list))
   (foreach miembro files
       (if 
           (setq write (open miembro "a"))    
           (progn
               (close write)
               (write-line (car command_list) write_scr)
               (write-line (strcat "\"" miembro "\"") write_scr)
               (while (< cnt_1 cnt_cmd)
                   (write-line (nth cnt_1 command_list) write_scr)
                   (setq cnt_1 (+ cnt_1 1))
                   (princ)
               )
               (setq cnt_1 1)
           )
           (princ (strcat "\n" miembro))
       )
       (princ)
   )
   (close write_scr)
   (command "_.script" write_name)
)    
--------------------------------
(defun master
   ()
   (setq xxxx "")    
   (setq yyyy "")    
   (while (= xxxx "")
       (lst_files)
       (setq xxxx (getstring "Enter whatever key or enter to keep looking for files"))
   )
   (while (/= yyyy "")
       (cmmd)
       (setq yyyy (getstring "Enter whatever key or enter to keep looking for files"))        
   )
   (run)    
)
--------------------------------
(master)

 

Thanks again

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...