Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Script to execute lisp on multiple drawings

  1. #1
    Member jrd.chapman's Avatar
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    49
    Login to Give a bone
    0

    Default Script to execute lisp on multiple drawings

    I am hoping to write a script to run a lisp function on multiple drawings. I'm not sure how to accomplish this though. I need the user to first be prompted to select the directory containing drawings to be processed, and then have the script run on each drawing in that directory.

    I have a small function written that allows the user to select the directory. Then all drawings in that directory are compiled into a list.

    Now that the user has specified what to process, I'm not sure where to go. I don't know how I can now use a script to open a drawing in this directory, run the Lisp routine that needs to be run, then save, close, and move onto the next drawing in the directory.

    Does anyone have any advice? I know this can be accomplished easier in VBA, but I would prefer to use a script.

    Any advice?

    Thanking you in advance

  2. #2
    Member
    Join Date
    2001-10
    Posts
    34
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    http://www.pellacad.com/sm80-password.htm

    ScriptMan Pro does pretty much what you need plus a whole lot more!

    ...and it's fast and easy to use.

    Pete
    pellacad@kdsi.net


    (I need help with DCL files...know anything about them?)

  3. #3
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Hi John, You have to combine the list of drawings and the list of commands in one script file, like :

    open
    "C:\MyMap\MyDrawing_1.dwg"
    commands . . .
    .CLOSE Y or N
    open
    "C:\MyMap\MyDrawing_2.dwg"
    commands . . .
    .CLOSE Y or N
    open
    "C:\MyMap\MyDrawing_3.dwg"
    commands . . .
    .CLOSE Y or N

    : ) Happy Computing !

    kennet

    by the way check out ScriptMan Pro or anything similar

  4. #4
    100 Club Lemons's Avatar
    Join Date
    2001-06
    Location
    Beautiful Charleston, SC
    Posts
    182
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Hi, John!!! Long time no see

    Why don't you just use ScriptPro?

    Celie

  5. #5
    Member
    Join Date
    2015-12
    Location
    Illinois
    Posts
    38
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    I had done this several years ago by using two text files. One contained a list of the files I was applying the change to. The other was just a counting file that was used to tell the lisp program what line to read in the list.

    I did this to read in dxf files and save each as a drawing:

    Code:
     
    ;Program to read a dos text file of a directory listing of dxf files.
    ;used to read dxf files into AutoCad.
    (defun S::STARTUP ()
       (readdxf)
    )
    (defun *error* ()
       (close cntfile)
       (close dxflist)
       (princ)
    )
    (defun readdxf ()
       (setq cntfile (open "i:/testdxf/testcnt.txt" "r"))
       (setq filecnt (read-line cntfile))
       (setq dxflist  (open "i:/testdxf/test.txt" "r"))
       (repeat (1- (atoi filecnt))
    	  (setq testread (read-line dxflist))
       );endrepeat
       (setq testread (read-line dxflist))
       (strip)
       (princ dxfread)
       (command "dxfin" dxfread)
       (command "saveas" dwgread)
       (setq filecnt (1+ (atoi filecnt)))
       (close cntfile)
       (close dxflist)
       (setq cntfile (open "i:/testdxf/testcnt.txt" "w"))
       (princ (rtos filecnt 2 0) cntfile)
       (close cntfile)
       (command "new"  "")
       (princ)
    )
    ;Program to strip the file extension and add prefix "I:/testdxf/" to filename. Example: Readme.txt=I:/testdxf/Readme
    ;also adds prefix "I:/testdxf/dwgs/" to filename. Example: Readme.txt=I:/testdxf/dwgs/Readme
    (defun strip ()
       (setq cnt 1)
       (while (not (equal (substr testread cnt 1) "."))
    	  (setq cnt (1+ cnt))
       );endwhile
       (setq dxfread (strcat "I:/testdxf/" (substr testread 1 (1- cnt))))
       (setq dwgread (strcat "I:/testdxf/dwgs/" (substr testread 1 (1- cnt))))
       (princ)
    )
    The lisp routine was part of the ACAD.lsp file which automatically ran each time a drawing was opened. This was used back in version 13 and I cant guarantee it would even work in todays environment.

  6. #6
    Member jrd.chapman's Avatar
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    49
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Thanks for all the replies guys.

    Ron, I will try your method when I have a chance, that is an interesting approach!

    Hi Celie, yes it has been a while!! As for ScriptPro, I thought that only came with AutoCAD 2000 Migration Assistance....Now, I'm on 2005 and it does not seem to be included anywhere. Is there somewhere I can still get it?

    Kennet, Yeah, I know I have to combine evryrhing into one script, but, the list of drawings needs to be created by the user, byt selecting a directory, and then having the script step throught hat directory from one drawing to the next. I'm not in a situation where I can just manually list each drawing in the script. I have hundreds of drawings to process, and I want this to be used in the future. I'm not sure how to incorporate the list (created with LISP), into the script.

    naschkeps, thanks for the link, I will check out ScriptMan Pro.

  7. #7
    I could stop if I wanted to tyshofner's Avatar
    Join Date
    2004-03
    Location
    Dallas, Tx
    Posts
    229
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Just to let you know there is a ScriptPro for '05. I'm posting a link but I'm new so I hope it works. If not you can find these on Autodesk's web site, just go to support, choose AutoCAD and then there should be a link on the left called "Data & Downloads" click on that, then on tools, then on Migration Assistance. Here is my link, hope it works.

    http://usa.autodesk.com/adsk/servlet...linkID=2475161

  8. #8
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Hi John, here is a simple and easy code for You to modify. It generate one scriptfile including dwg files in a selected directory and command lines to execute on each of them.
    Code:
    (defun c:MakeMyScript ( / UserFile UserCat FileList File#1 Index FileName )
      (vl-load-com )
      (setq UserFile (getfiled "Find the the catalog with the drawings to process, and pick one file" "*.*" "*" 16 ) )
      (setq UserCat  (vl-filename-directory UserFile ) )
      (setq FileList (vl-directory-files UserCat "*.dwg" 1 ) )
    ; ^- those 3 command lines generate a list like ("chroma.dwg" "direct.dwg" "overhead.dwg" "rm_sdb.dwg" "sh_spot.dwg")
    ; then You need lines, a list or a txt file with the commands to execute on each drawing
    ; make a while loop and step trough the file list and add the command lines to each file while writing to the script file
      (setq File#1 (open "c:/MyTest.scr" "w" ) ) ;; open/make a scriptfile to write to
      (setq Index 0 )
      (while (setq FileName (nth Index FileList ) ) ;; loop trough every dwg in FilList
        (princ (strcat "open " FileName "\n" ) File#1 )
        ;; write Your command lines here , those lines is NOT tested to run
        (princ "._zoom ext \n" File#1 )
        (princ "._-layer s 0 \n" File#1 )
        (princ "close Yes or No \n" File#1 )
        (setq Index (1+ Index ) ) ;; prepare for next file to loop
      )
      (close File#1 )
      (princ "open c:/MyTest.scr and look at it" )
      (startapp "NOTEPAD" "c:/MyTest.scr" )
      (princ)
    )
    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2005-02-04 at 12:20 AM.

  9. #9
    Member jrd.chapman's Avatar
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    49
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    tyshofner, Thanks very much for that link, much appreciated!!

    Kennet!!!!! That is wonderful!!! That is exactly what I was trying to accomplish, I was getting hung up on actually writing the script after generating the file list...you have unlocked that mystery for me!!!

    Thank you again so much.

    Thank you to everyone for their insight. Once again I have learned something from the wonderful people here!

    Take care!

  10. #10
    Member jrd.chapman's Avatar
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    49
    Login to Give a bone
    0

    Default Re: Script to execute lisp on multiple drawings

    Just thought I'd share the finished product. Modified Kennet's code (thank you so much again kennet...what I've learned about creating a script from within Lisp is invaluable and I will use it a lot in future applications...)

    It is working like a charm so far....Here is what I came up with:
    Code:
    (defun c:BatchLock
    	   (/ UserFile UserCat FileList File#1 DwgName FileName)
      (vl-load-com)
      (setq UserFile
      (getfiled "Select a drawing within the directory to process"
    	 "c:/"
    	 "dwg"
    	 16
      )
      )
      (setq UserCat (vl-filename-directory UserFile))
      (setq FileList (vl-directory-files UserCat "*.dwg" 1))
      (setq File#1 (open "c:/Lockup.scr" "w"))
      ;; open/make a scriptfile to write to
      (foreach DwgName FileList
    	(setq FileName (strcat "\"" UserCat "\\" DwgName "\""))
    	(princ "open\n" File#1)
    	(princ (strcat FileName "\n") File#1)
    	;;Below are commands to run on each drawing...	
    	(princ "audit\n" File#1)
    	(princ "Y\n" File#1)
    	(princ "(load \"BatchLockRun.vlx\")\n" File#1)
    	(princ "(C:BATCHLOCKRUN)\n" File#1)
    	(princ "audit\n" File#1)
    	(princ "Y\n" File#1)
    	(princ "_.qsave\n" File#1)
    	(princ "_.close\n" File#1)
      )
      (close File#1)
      (command "script" "C:\\Lockup.scr")
      (princ)
    )
    (princ "\nBatchLock loaded.")
    (princ)
    Thanks again to everyone for their help!!

Page 1 of 2 12 LastLast

Similar Threads

  1. 2015: AutoCAD LT Script that changes multiple attributes across multiple drawings
    By alecgburke704194 in forum AutoCAD LT - General
    Replies: 1
    Last Post: 2015-06-30, 12:21 PM
  2. Script for changing UCS in multiple drawings
    By marcusnewport in forum AutoCAD General
    Replies: 2
    Last Post: 2010-05-25, 01:56 PM
  3. How to run a LISP routine on multiple drawings?
    By jmoore284 in forum AutoLISP
    Replies: 3
    Last Post: 2008-05-06, 05:24 AM
  4. Updating multiple computers using a script or LISP file
    By Chris.Partin in forum AutoCAD Customization
    Replies: 9
    Last Post: 2007-08-22, 04:34 PM
  5. Execute AutoCAD through a VB Script file (.vbs)?
    By abdulhuck in forum VBA/COM Interop
    Replies: 5
    Last Post: 2007-02-22, 06:16 AM

Posting Permissions

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