See the top rated post in this thread. Click here

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Excel file with drawing locations and Open up those drawings

  1. #11
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    1

    Default Re: Excel file with drawing locations and Open up those drawings

    Quote Originally Posted by carl_hd_collins
    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.

    Code:
    (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:
    Code:
    (setq dwgName (strcat "\"" dwgpath (nth count dwgList) "\""))
    Regards,
    Abdul Huck

  2. #12
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    Quote Originally Posted by Lions60
    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.

    Quote Originally Posted by Lions60
    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

  3. #13
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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.

  4. #14
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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."

  5. #15
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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.

  6. #16
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    Quote Originally Posted by Lions60
    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.

    Quote Originally Posted by Lions60
    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

  7. #17
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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.
    Attached Files Attached Files

  8. #18
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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

  9. #19
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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.

  10. #20
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Excel file with drawing locations and Open up those drawings

    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

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2012-08-08, 05:50 PM
  2. Replies: 3
    Last Post: 2012-06-17, 09:42 PM
  3. Excel - Cannot Open A Pasted Excel File
    By omorah in forum AutoCAD General
    Replies: 2
    Last Post: 2008-08-08, 06:50 PM
  4. Excel Formula to open drawing layout tab
    By wpeacock in forum AutoCAD General
    Replies: 3
    Last Post: 2008-07-23, 05:29 PM
  5. get already open excel file
    By jcoon in forum VBA/COM Interop
    Replies: 2
    Last Post: 2004-08-22, 04:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •