Good Day! I am new to posting in this forum, or any forum for that matter, please forgive any errors I may make at this time, or if I'm too wordy. I use AutoCAD 2010, if that has any bearing on any of this. I have experience in writing lisp routines and macros, mostly by taking pieces of others' routines and adapting them to my needs. But alas, I am needing help with a lisp routine that reads from a text file that contains a list of numbers, copy/pasted from excel, where each number represents existing directories and drawing names, i.e.: J:\123456\123456.dwg. The end point is that each drawing in each directory will be opened and a lisp routine run on it to plot a small image of one of the multiple tabs, (I have this part working just fine), and then closing it and opening the next in the list and so on till the end of the list. I am thinking from reading a lot of other info on a number of forums that a script would work well in this situation, but I can't seem to get all the pieces in place. Perhaps it may help if you know that the example of the directories and drawing number I gave above are the contents of cells in an excel file, I have a VBA macro that turns the raw numbers into hyperlinks to open the drawings from excel. I do have some code, but what code I do have is not for public consumption and would confuse the question for all, mostly me. Any help would be greatly appreciated!
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Here is a simple example to get you started:
(defun c:test ( / fd1 fd2 scr txt ) (if (and (setq txt (getfiled "Select Text File" "" "txt" 0)) (setq scr (getfiled "Create Script File" "" "scr" 1)) (setq fd1 (open txt "r")) (setq fd2 (open scr "w")) ) (progn (while (setq str (read-line fd1)) (write-line (strcat "_.open \"" str "\" " "(load \"C:\\\\YourLISP.lsp\" nil) " "(if c:YourCommand (c:YourCommand)) " "_.qsave _.close" ) fd2 ) ) (close fd1) (close fd2) ) ) (princ) )
Thank you Mr. Mack! I will try you code and let you know what happens. I appreciate your assistance! BTW, I've read many an answer by you and have used a number of your excellent routines!
Thank you Mr. Mack! I will try you code and let you know what happens. I appreciate your assistance! BTW, I've read many an answer by you and have used a number of your excellent routines!
You're most welcome Joe -
Let me know if you have any questions about the code and I'll be happy to explain.
I'm glad to hear you have benefited from my posts around the web!
Lee
Lee,
It's working fine in testing, but I have a dialog box called whenever a drawing is opened and the option to publish when closing any drawing. Would a call to "FILEDIA" be appropriate somewhere in the lisp so that I wouldn't need to click "Cancel" on one and "No" on the other while the script is running? If so, where would I locate it?
Joe
-Edit- Tried this inside the lisp and it didn't work.
Hi Joe,
If you intend to batch process an AutoLISP program from an AutoCAD Script, the program will need to be designed to evaluate without user input. Without seeing the program that you are attempting to run with the Script, it is difficult for me to advise how best to resolve your issue.
Lee
Thanks Lee,
I have attached the lisp files. As you will see, Test1 calls myplot-face in the script, gochngplt is called at the startup of each drawing and is a dialog box.
Thank you again!
Joe
OK, to avoid the gochngplt function being evaluated on drawing startup whilst the Script is running, try changing the following portion:
( (lambda ( ) (vl-load-com) (if (= 'list (type s::startup)) (if (not (member '(C:gochngplt) s::startup)) (setq s::startup (append s::startup '((C:gochngplt)))) ) (defun-q s::startup nil (C:gochngplt)) ) (princ) ) )
To:
( (lambda ( ) (vl-load-com) (if (zerop (logand 4 (getvar 'cmdactive))) (if (= 'list (type s::startup)) (if (not (member '(C:gochngplt) s::startup)) (setq s::startup (append s::startup '((C:gochngplt)))) ) (defun-q s::startup nil (C:gochngplt)) ) ) (princ) ) )
I can't offer any advice where the publish option is concerned, as I am unsure what is triggering this to appear on drawing close.
Lee,
I will try your suggestion when I get in to work in the morning. As for the publish dialog, I have it enabled to ask if I want to auto publish the drawing before closing, and I will uncheck the box for that when I'm running the script.
You've been a huge help with this, thank you!
Joe
You're welcome Joe - I hope all goes well.
Lee,
Unfortunately the change to GOCHNGPLT did not work. But it is working very fine other than that. Would you have another suggestion for that? And I'm wondering what the idea was there, I had a difficult time trying to figure it out. And I didn't note in that section of the routine that I got that part from another of your routines, I have fixed that. Or, is it only proper to credit the author for a whole routine?
I have a question about a different routine that you put together for someone else. Should I ask that in a new post?
Joe
Unfortunately the change to GOCHNGPLT did not work. But it is working very fine other than that. Would you have another suggestion for that? And I'm wondering what the idea was there, I had a difficult time trying to figure it out.
That's a shame -
The CMDACTIVE system variable should have bitcode 4 set when a Script is active, therefore, my modification tests whether this bitcode is set and only defines the s::startup function if the bit is not set.
Though, after some testing, it would appear that the CMDACTIVE system variable remains at zero when evaluated from within the acaddoc.lsp whilst a Script is running, but has bitcode 4 set by the time the s::startup post-initialisation function is evaluated (whilst the Script is running).
With this knowledge, I would suggest changing:
( (lambda ( ) (vl-load-com) (if (= 'list (type s::startup)) (if (not (member '(C:gochngplt) s::startup)) (setq s::startup (append s::startup '((C:gochngplt)))) ) (defun-q s::startup nil (C:gochngplt)) ) (princ) ) )
To:
( (lambda ( / expr ) (vl-load-com) (setq expr '((if (zerop (logand 4 (getvar 'cmdactive))) (c:gochngplt)) (princ))) (if (= 'list (type s::startup)) (setq s::startup (append s::startup expr)) (eval (vl-list* 'defun-q 's::startup 'nil expr)) ) (princ) ) )
And I didn't note in that section of the routine that I got that part from another of your routines, I have fixed that. Or, is it only proper to credit the author for a whole routine?
I did recognise the code
In general, if you have directly copied any portion of code from a program written by another author, it is usually good coding etiquette to include a note indicating the original author and/or source of the code, otherwise all uncredited code is assumed to be your own.
I have a question about a different routine that you put together for someone else. Should I ask that in a new post?
If the new question is unrelated to the question you have posed in this thread, then yes, it belongs in a separate thread (or within an existing appropriate thread on the same topic).
Lee
Lee,
I will try out the new code you've added shortly and let you know how it worked. Thank you for the explaination of the code and about crediting of authors in lisp routines.
On another note, how do you get the yellow boxes with portions of messages that are being responded to? Tricky stuff.
Joe
I will try out the new code you've added shortly and let you know how it worked. Thank you for the explaination of the code and about crediting of authors in lisp routines.
You're most welcome Joe!
On another note, how do you get the yellow boxes with portions of messages that are being responded to? Tricky stuff.
One of the perks of being recognised as an 'Expert Elite' is the ability to use div/span HTML tags in forum posts
Lee
Ah, I see, and you use it wisely I might ad.
I did try the latest change on the GOCHNGPLT routine and the dialog box still pops up while running the script. One time trying it, the script got struck, ran it again immediately follwing and it worked but still with the pop up. Perhaps I should remove the s::startup section when running it and put it back in when not using the script? If you wish to try again, please do, otherwise I'm fine with the way it is.
Joe
While the script is running, the cmdactive system varible shows "0", no command active, instead of "4", script is active.
Is there an escape key call to place in the script when my lisp is paused for user input while the script is running? Ideally the dialog box should not show up at all during the script, but escaping the dialog box without user input would be an acceptable workaround.