View Full Version : Excel file with drawing locations and Open up those drawings
Lions60
2006-07-25, 02:00 PM
I was just wondering if there was a way to get autocad to take an excel file with drawing locations and open up these drawings, run specified lisp programs, then save and close these files as dxf's to the correct directory. If anyone can help I would appreciate it. There is no code because i have no idea where to start.
rkmcswain
2006-07-25, 02:09 PM
That shouldn't be too difficult, however is it necessary to store this information in Excel format? If it's just a list of drawings, reading from a .TXT file would be easier.
You could also create a script file to make the edits you want, then use ScriptPro from Autodesk to run this script on multiple drawings.
Lions60
2006-07-25, 03:05 PM
No it is not necessary to use an excel file it was basically just an example of a format. A .txt file would be sufficient. I am just trying to save time because i have 2000 drawings i need to open and convert with certain lisp commands and thought maybe i could do a type of batch run. I am not familiar with script files of ScriptPro.
Avatart
2006-07-25, 04:03 PM
You can get into Excel data more easily with VBA, but if you want to use Lisp, you could try using a .csv file, that can be read line by line by AutoCad and is readable to Excel, I use this quite alot.
I wrote a program a little while back to place colour coded luminance values at specified locations across a site, I have attached it here with a little "how-to" and some sample data all wrapped up in a zip file, feel free to plagiarise it all you want (a credit would be nice though). Hope it helps you get started.
Lions60
2006-07-25, 04:25 PM
I'm sorry that is a bunch of foreign language to me I am fairly new at being introduced to Lisp and can do some basic routines, but nothing of this stature. Thanks for your help if I knew what i was doing it would probably help a whole lot more. The thing is that i can see in my head what i want it to do but can't put it down.
The program just needs to open up drawings from any sort of text file, run certain lisp commands and save as .dxf and close. Also this has to be done over 2,000 files.
Again thanks for all the help.
I'm sorry that is a bunch of foreign language to me I am fairly new at being introduced to Lisp and can do some basic routines, but nothing of this stature. Thanks for your help if I knew what i was doing it would probably help a whole lot more. The thing is that i can see in my head what i want it to do but can't put it down.
The program just needs to open up drawings from any sort of text file, run certain lisp commands and save as .dxf and close. Also this has to be done over 2,000 files.
Again thanks for all the help.
Don't worry about the 2000 files for the moment. Write down in plain english what you want to accomplish. Those steps can then be broken down into smaller steps. These smaller steps are the basis of your program. The syntax isn't that difficult.
Here are some similar threads that may help.
Script to execute lisp on multiple drawings
I want to Open a file
Lions60
2006-07-25, 06:24 PM
Ok i have ScriptPro on my computer now i need to know what is included in a script and how to write one. Is it the same as an autolisp routineand if so can i jsut paste the routine in.
abdulhuck
2006-07-26, 09:43 AM
Hi,
You can try the following code. I have tried to explain it in detail.
(defun c:GenScr (/ dwgPath dwgList dwgName numDwgs count scrFile)
;;; Path should be like "c:\\projects\plots\\" or "c:/projects/plots/"
;;; Substitute your path here.
(setq dwgPath "C:\\projects\\plot\\" ; sets the path
dwgList (vl-directory-files dwgPath "*.dwg") ; get the list of all the drawings
)
(if dwgList ; if dwg files exists there
(progn
(setq numDwgs (length dwgList) ; number of drawings
count 0 ; initiate counter
scrFile (open (strcat dwgPath "Runme.scr") "w") ; open a script file in the same folder
)
(repeat numDwgs ; for all the drawings
(setq dwgName (strcat dwgpath (nth count dwgList)))
(write-line ".Open" scrFile) ; write to script file
(write-line dwgName scrFile)
;;;If you need to load a lisp routine in each dwg
(write-line "(load \"MyLispFile.Lsp\")" scrFile) ; load any required lisp routine
;;;
;;; Enter your commands here.
(write-line "MyCommand" scrFile)
;;;
;;; Preset the dxf file format before you proceed.
;;; May require minor modification depending on you
;;; AutoCAD version Notice the two spaces after dxfout
;;; in the following line acts like <enter>.This will
;;; accept the default file name and default format
(write-line ".Dxfout " scrFile)
;;; Better to save the drawing for uninterrupted scripting
(write-line ".Qsave" scrFile)
(setq count (1+ count)) ; next dwg
)
(close scrFile) ; close when done
;;; Make sure that the current dwg won't prompt for
;;; save changes!
(command ".script" (strcat dwgpath "Runme.scr")) ; run the script
) ; progn
) ; if
(princ)
) ; defun
Hope this will serve your purpose.
Regards,
Abdul Huck
Avatart
2006-07-26, 10:12 AM
Nice little piece of coding, Abdul. Note that what Abdul has written is a Lisp routine and not a script, so you will have to APPLOAD it and run it, rather than SCRIPT and run.
I think I can infer from the ealier posts that there is a large number of drawings to be processed here, are they all in one directory? Abdul's program seems to work on this basis (correct me if I am wrong, please Abdul), are your drawings all in one place, or do you have the text file that lists out all their locations? It would not be too difficult to read the text file line by line and work in multiple folders.
Lions60
2006-07-26, 01:42 PM
Currently I have all of the drawings in one directory for the ease of me finding which ones i need to change. I do understand that Abdul's code is a lisp routine but in it he keeps calling out a script file. Is this something already in ACad or is this where i would list a script file if one was written. I do thank you for the code it gives me some insight on what's going on. The part that say "enter my commands here" what commands do i enter because the lisp routines should be taking care of everything i need done in the drawing. Or is this where i could load multiple lisp routines.
abdulhuck
2006-07-26, 02:02 PM
I think I can infer from the ealier posts that there is a large number of drawings to be processed here, are they all in one directory? Abdul's program seems to work on this basis (correct me if I am wrong, please Abdul), are your drawings all in one place, or do you have the text file that lists out all their locations? It would not be too difficult to read the text file line by line and work in multiple folders.
Thanks for your feedback Collins. You are right. Here we go for a text file having the path\filename format.
(defun c:GenScr2 (/ wrkPath dwgList dwgName scrFile)
;;;
;;; This code assumes that you have a text file having file names including path
;;; i.e, C:\\PROJECTS\\PLOT\\DRAWING1.DWG
;;; If you wish to create a text file including path and sub folders, use the dir
;;; command at dos prompt (of the root folder of the drawings) as below:
;;; "DIR *.DWG /B /S /O >c:\work\DrawingList.txt"
;;; This will create a text file called DrawingList.txt in c:\work
;;;
;;; Better to assing a work folder
(setq wrkPath "C:\\Works\\")
;;;
;;; Now open the text file for reading
(setq dwgList (open (strcat wrkPath "DrawingList.txt") "r") ; substitute your path
scrFile (open (strcat wrkPath "Runme.scr") "w") ; open a script file
)
(while (setq dwgName (read-line dwgList)) ; loop till the end of file
;;;
;;; In case your path/file name contains spaces add the following line
;;; (Applicable for the previous code also)
(setq dwgName (strcat "\"" dwgName "\""))
(write-line ".Open" scrFile) ; write to script file
(write-line dwgName scrFile)
;;;If you need to load a lisp routine in each dwg load it here
(write-line "(load \"MyLispFile.Lsp\")" scrFile) ; load any required lisp routine
;;;
;;; Enter your commands here.
(write-line "MyCommand" scrFile)
;;;
;;; Preset the dxf file format before you proceed.
;;; May require minor modification depending on you
;;; AutoCAD version Notice the two spaces after dxfout
;;; in the following line acts like <enter>.This will
;;; accept the default file name and default format
(write-line ".Dxfout " scrFile)
;;; Better to save the drawing for uninterrupted scripting
(write-line ".Qsave" scrFile)
) ; while
(close dwgList)
(close scrFile) ; close when done
;;; Make sure that the current dwg won't prompt for
;;; save changes!
(command ".script" (strcat wrkpath "Runme.scr")) ; run the script
(princ)
) ; defun
Please note that I forgot to add quotation marks (") for the file names in the previous code posted. This is required if the path/file name contains spaces. Otherwise the script file will treat it as an <enter>. Substitute the following line instead of (setq dwgName (strcat dwgpath (nth count dwgList) )) in the previous code if somebody wish to use it:
(setq dwgName (strcat "\"" dwgpath (nth count dwgList) "\""))
Regards,
Abdul Huck
abdulhuck
2006-07-26, 02:28 PM
Currently I have all of the drawings in one directory for the ease of me finding which ones i need to change. I do understand that Abdul's code is a lisp routine but in it he keeps calling out a script file. Is this something already in ACad or is this where i would list a script file if one was written.
Dear Lions60 (sorry I don't know your real name),
If your drawings are in one place, you can use the first code I posted, with a minor modification mentioned in the second post, i.e, if you have spaces in the path, then the script won't run. All you need to do is to give the path of your drawing files instead of "C:\\PROJECTS\\PLOT\\" which I used for testing the program. The routine will generate a list of all the drawings in that folder and create a script file, which will be executed at the end automatically. Please note that I have not included any checking for read-only attributes. It is assumed that the folder or files are NOT read only.
The part that say "enter my commands here" what commands do i enter because the lisp routines should be taking care of everything i need done in the drawing. Or is this where i could load multiple lisp routines.
Please note that the line (write-line "(load \"MyLispFile.Lsp\")" scrFile) only loads your lisp routine to each opened drawing. You can repeat this line for any number of files and change the MyLispFile.lsp to the corresponding file name. After loading the lisp files, next line, i.e. (write-line "MyCommand" scrFile) calls the command defined in your lisp file. You have to substitute MyCommand with the command in the loaded lisp file. This line also should be repeated till all your commands are done. In other words, one line for each command.
Hope this will clear your doubts.
Regards,
Abdul Huck
Lions60
2006-07-26, 02:37 PM
ok i have tried running the "DIR *.DWG /B /S /O >c:\work\DrawingList.txt" in the dos prompt but it won't allow me to locate the folder on my desktop so i can make a text file.
Lions60
2006-07-26, 02:42 PM
So where my command is written i substitute that for the command i type in autocad to start the lisp routine. Suchas i have a routine (defun mylisp()) Instead of "MyCommand" I wouldreplace it with "Mylisp."
Avatart
2006-07-26, 02:47 PM
Lions, you are right in what you say about the "MyCommand" "MyLisp" replacement. I don't understand why you want to write the script file from the Dos prompt though, why not do it in Notepad? If you need to check code as you go, you can write using the VLIDE in AutoCad.
abdulhuck
2006-07-26, 03:00 PM
ok i have tried running the "DIR *.DWG /B /S /O >c:\work\DrawingList.txt" in the dos prompt but it won't allow me to locate the folder on my desktop so i can make a text file.
Please make sure that you have C:\Work in your system. If not, use any folder of your choice. All the folder names in that routine are tentative only. You need to update them as per your requirement.
So where my command is written i substitute that for the command i type in autocad to start the lisp routine. Suchas i have a routine (defun mylisp()) Instead of "MyCommand" I wouldreplace it with "Mylisp."
If your command is (defun mylisp(), then you need to substitute (mylisp). If it was (defun c:mylisp ()
then you could have used "mylisp" (without brackets).
Regards,
Abdul Huck
Lions60
2006-07-26, 03:14 PM
ok abdulhuck I really appreciate your help thus far. I have taken your code and substituted where needed but when the program is run and it gets to the ".QSAVE" it asks me for accuracy of decimal places so i enter a number then it says the file it has open can't be opened.
Attached is a screen shot.
abdulhuck
2006-07-26, 03:34 PM
Please make sure that there are two spaces after the dxfout command as shown below.
(write-line ".Dxfout " scrFile) -> should read
(write-line<space>".dxfout<space><space>"<space>scrFile)
If you had copied and pasted the code, it should work fine. Spaces work like <enter> key in script file.
Regards
Abdul Huck
Lions60
2006-07-26, 04:28 PM
I have encountered a problem. Autocad keeps running out of memory after about 200 drawings being opened. Is there a way you can open the drawing do what needs to be done, save, and close the drawing before the next one opens.
Lions60
2006-07-26, 04:56 PM
ok i got it to where it opens the drawings and saves and closes them. I know all of my lisp routines work because i had already done about a hundred manually so i don't know if its not saving the changed dxf's or if my programs are just missing a few lines in each dxf. But its working right now and i am just running the programs one at a time instead of all at once thinking this will fix the problem. Thanks for everyone's help I will keep posting updates
Lions60
2006-07-26, 05:13 PM
got a problem. When i run the lisp it opens the first drawing runs lisp programs until it get to the one i have call convert line to plines and then the program stops and doesn't save or close or open anyother drawings. Maybe it is in the code i have written here it is along with the script code.
(defun CONVERT (/ OLDVAR1 LCOLOR COUNT LINENO SS1 ENT EDATA PT1 PT2)
(command ".undo" "Mark")
(setq old_plinetype (getvar "PLINETYPE"))
(setvar "PLINETYPE" 0)
(setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
(setvar "PLINEWID" 0)
(setq SS1 nil)
(setq SS1 (ssget "X" ' ((0 . "LINE"))))
(setq LINENO (sslength SS1))
(setq COUNT 0)
(setq PLINFO (ssadd))
(repeat LINENO
(progn
(setq ENT (ssname SS1 COUNT))
(setq EDATA (entget ENT))
(setq PT1 ( cdr (assoc 10 EDATA)))
(setq PT2 ( cdr (assoc 11 EDATA)))
;(setq LCOLOR (cdr (assoc 62 EDATA)))
(setq LLAYER (cdr (assoc 8 EDATA)))
;(if LCOLOR (princ) (setq LCOLOR "BYLAYER"))
(command "Color" LCOLOR )
(command "Layer" "s" LLAYER "")
(command "Pline" PT1 PT2 "")
(ssadd (entlast) PLINFO)
(prompt (strcat "Processing line no. " (itoa COUNT) "\r"))
(setq COUNT (1+ COUNT))
)
)
(COMMAND "ERASE" SS1 "")
(setvar "CMDECHO" OLDVAR1)
(prompt (strcat "\n" "Erasing original lines..." "\n"))
(princ) ; end program
(setvar "PLINETYPE" old_plinetype)
); end convert.lsp
Script code:
scrFile (open (strcat dxfPath "Runme.scr") "w") ; open a script file in the same folder
)
(repeat numDwgs ; for all the drawings
(setq dwgName (strcat "\"" dxfpath (nth count dwgList) "\""))
(write-line ".Open" scrFile) ; write to script file
(write-line dwgName scrFile)
;;;If you need to load a lisp routine in each dwg
;(write-line "(load \"Setting layer '0' current with continuous Ltype.LSP\")" scrFile) ; load any required lisp routine
;(write-line "(load \"Arcs to plines.lsp\")" scrFile) ; load any required lisp routine
;(write-line "(load \"Circles to PLines.LSP\")" scrFile) ; load any required lisp routine
(write-line "(load \"Converting Lines to Polylines.LSP\")" scrFile) ; load any required lisp routine
(write-line "(load \"Explode all.LSP\")" scrFile) ; load any required lisp routine
(write-line "(load \"Light-weight PLines to 2D PLines.LSP\")" scrFile) ; load any required lisp routine
;;;
;;; Enter your commands here.
;(write-line "(con)" scrFile)
(write-line "(ex)" scrFile)
(write-line "(convert)" scrFile)
;(write-line "(arctopl)" scrFile)
;(write-line "(c2p)" scrFile)
(write-line "(2d)" scrFile)
;;;
;;; Preset the dxf file format before you proceed.
;;; May require minor modification depending on you
;;; AutoCAD version Notice the two spaces after dxfout
;;; in the following line acts like <enter>.This will
;;; accept the default file name and default format
(write-line ".Dxfout " scrFile)
;;; Better to save the drawing for uninterrupted scripting
(write-line ".Qsave" scrFile)
(write-line ".close" scrFile)
(setq count (1+ count)) ; next dwg
)
(close scrFile) ; close when done
;;; Make sure that the current dwg won't prompt for
;;; save changes!
(command ".script" (strcat dxfpath "Runme.scr")) ; run the script
) ; progn
) ; if
(princ)
) ; defun
Lions60
2006-07-27, 02:22 PM
ok here is an update. I have gotten everything to work perfectly, and I want to thank everyone who helped on this. I appreciate it very much you all saved me about 2 months worth of work. But now i do want to throw out another issue i am having. I am trying to convert all ellipses in these drawings to plines and the program works great on actual ellipses, but when it comes to the elliptical arcs the program draws a full ellipse and doesn't trim or break it back to look like an arc. If anyone can help with this it would be much appreciated too.
Mike.Perry
2006-07-27, 10:15 PM
<SNIP> But now i do want to throw out another issue i am having. I am trying to convert all ellipses in these drawings to plines and the program works great on actual ellipses, but when it comes to the elliptical arcs the program draws a full ellipse and doesn't trim or break it back to look like an arc. If anyone can help with this it would be much appreciated too.Hi
If anyone can offer assitance / help on the above request, please do so here...
How to Change elliptical arcs into Polylines
Thanks, Mike
Forum Manager
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.