andr3flaviano Posted May 15, 2017 Posted May 15, 2017 Hello, guys! I'm new here. So, please, be gentle. I had a problem with a routine. I have to open all the drawings in the same folder, compare a specific area of the drawing with a reference and change that area, if necessary. But I have a lot of references to compare, so I need to do that many times. I've already got a batch to open all the drawings in the same folder. So I just modified it to compare the area with the reference and it worked greatly. The only problem is: When i put that batch inside a loop instruction (to change the reference that will be compared), the batch didn't worked. The following error appears: ; error: bad argument type: streamp nil Here goes the code. Could someone help me? (defun c:testloop (/) (setq c 1) (while ( (c:opendrawings) (setq c (1+ c)) ); end while ); end function to test the loop (defun c:opendrawings (/ dwglist dwgname dwgpre file openfile uhoh len) (vl-load-com) (if (and (setq dwgpre (getvar 'dwgprefix)) (setq dwglist (vl-sort (vl-remove (strcat dwgpre (getvar 'dwgname)) (mapcar '(lambda (dwgname) (strcat dwgpre dwgname)) (vl-directory-files dwgpre "*.dwg") ) ) ' ) ) (setq uhoh "Readonly drawings will not be processed!" ) (setq len (strlen uhoh)) ) (progn (setq openfile (open (setq file (strcat dwgpre "myscript.scr")) "w")) (progn (foreach f dwglist (if (and (not (Is_ReadOnly f)) (/= (checkAttFile f) 1) ) (progn (write-line (strcat "_.open \"" f "\"") openfile) (write-line "_.audit _y" openfile) ; (write-line "_.qsave _.close" openfile) ) (setq uhoh (strcat uhoh "\n" f)) ) ) (close openfile) (command "_.script" file) (if (= (strlen uhoh) len) (princ "All drawings successfully processed...") (alert uhoh) ) ) ) ) (princ) ); end function to open all the drawings Quote
Lee Mac Posted May 15, 2017 Posted May 15, 2017 The "streamp nil" error indicates that your 'openfile' variable is null when write-line is evaluated. Quote
SLW210 Posted May 15, 2017 Posted May 15, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
andr3flaviano Posted May 15, 2017 Author Posted May 15, 2017 Ok! Sorry. Hello, guys! I'm new here. So, please, be gentle. I had a problem with a routine. I have to open all the drawings in the same folder, compare a specific area of the drawing with a reference and change that area, if necessary. But I have a lot of references to compare, so I need to do that many times. I've already got a batch to open all the drawings. So I modified it to compare the area with the reference and it worked greatly. The only problem is: When i put that batch inside a loop instruction (to change the reference that will be compared), the batch didn't worked. The following error appears: ; error: bad argument type: streamp nil Here goes the code. Could someone help me? (defun c:testloop (/) (setq c 1) (while (<= c 5) (c:opendrawings) (setq c (1+ c)) ); end while ); end function to test the loop (defun c:opendrawings (/ dwglist dwgname dwgpre file openfile uhoh len) (vl-load-com) (if (and (setq dwgpre (getvar 'dwgprefix)) (setq dwglist (vl-sort (vl-remove (strcat dwgpre (getvar 'dwgname)) (mapcar '(lambda (dwgname) (strcat dwgpre dwgname)) (vl-directory-files dwgpre "*.dwg") ) ) '< ) ) (setq uhoh "Readonly drawings will not be processed!" ) (setq len (strlen uhoh)) ) (progn (setq openfile (open (setq file (strcat dwgpre "myscript.scr")) "w")) (progn (foreach f dwglist (if (and (not (Is_ReadOnly f)) (/= (checkAttFile f) 1) ) (progn (write-line (strcat "_.open \"" f "\"") openfile) (write-line "_.audit _y" openfile) ; <--- Here I put the routines that I need (write-line "_.qsave _.close" openfile) ) (setq uhoh (strcat uhoh "\n" f)) ) ) (close openfile) (command "_.script" file) (if (= (strlen uhoh) len) (princ "All drawings successfully processed...") (alert uhoh) ) ) ) ) (princ) ); end function to open all the drawings Quote
Roy_043 Posted May 16, 2017 Posted May 16, 2017 I do not see anything obviously wrong with the posted code. At what point does the code fail? Is the script created? Posting the code that has been left out may help. Quote
Recommended Posts
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.