+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Nov 2011
    Posts
    4

    Default Call multiple .scr files from list to create new AutoCad files

    Registered forum members do not see this ad.

    Hello,
    I have created script files to generate a complex shape in AutoCad from an excel file. Each .SCR file is unique. What I want to do is create a separate AutoCad file for each unique .SCR file (there are over 100 .scr files). Note that I do not want to run the same script on multiple files as is commonly done.

    I was thinking I could use a lisp routine to iterate through a list (.txt?) with the .SCR file names. For each .scr file in the list it would open a new .dwg file, run the script, do a few simple operations, save and close the file.

    I have no lisp experience but have some R and Matlab programming background.

    First: Is this possible?
    Second: Do you have any coding suggestions?

    Something like below is what I was thinking, excuse my abuse of syntax, I am a newbie.
    list=list.txt with .SCR file names

    Code:
    Command: (foreach entry list ;;list is a list of file names ex("Tree108.scr" "Tree205.scr" Tree356.scr")
                   (setq ent(vl-string-right-trim ".scr" "entry")) ; trim scr from current list element, I think,  store as ent
                   (Command: open "c:\\my documents\\ent.dwg" "w") ;; ent is entry - .scr
                   (Command: Filedia 0) ;;suppresses file dialogue box
                   (Command: SCRIPT entry) ;; entry is the file name (ex."Tree120.scr")
    	       (Command: _-view front) ;; view from front
                   (Command: zoom extents) ;; get all of tree in view
    	       (Command: Saveas "" ent) ;;save as, then "" for default?, then entry
    	       (Command: Close) ;;Close file, repeat for next enrty
    	) ;;end of foreach loop

  2. #2
    Luminous Being
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    5,458

    Default

    I think the code will stop after 1st command open what would be better would be to have your lisp rewrite the script each time its run and the very last line would be SCRIPT NEXTDWGETC.

    The lisp could read a txt file for dwg names you would need to save a variable say into the registry which tells you what the next line number is.

    Alternatively thinking now just create the txt file dwg names and write one big script then run it.

    Code:
    ;;; not tested !
    (Setvar "Filedia" 0)) ;;suppresses file dialogue box for all autocad sessions no need to do multiple.
    (setq fi (open mydwgfiles "R"))
    (setq fo (open "mydwgfiles.scr" "W"))
    (while (setq new_line (read-line fi))
    (write-line FO "open" (strcat "c:\\my documents\\" new-line ".dwg")) ;; xxx is dwg name
    ; filedia
    (write-line FO  " _-view front") ;; view from front
    (write-line FO  "zoom extents") ;; get all of tree in view
    (write-line FO  "Saveas new_line" ) ;;save as, then "" for default?, then entry
    (write-line FO   "Close Y") ;;Close file, repeat for next entry note "Y"
    )
    (close fo)
    (close fi)
    (command "script" "mydwgfiles")
    )
    A man who never made mistakes never made anything

  3. #3
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Nov 2011
    Posts
    4

    Default Follow up from BIGAL

    Hello BIGAL,
    I don't completely follow your logic. I've placed comments in the code where I am confused. What I gather is that I'll use a lisp routine to write one enormous script file with all my individual scripts copied in but with some open, save, and close statements between them.

    Code:
    (Setvar "Filedia" 0)) ;No problem here
    (setq fi (open mydwgfiles "R")) ;I don't have any dwg files yet, only different .scr files, should this be "mydwgfiles.txt" not mydwgfiles? is this a list containing the names of all my script files?
    (setq fo (open "mydwgfiles.scr" "W")) ;this must be the enormous script file I'll write to
    (while (setq new_line (read-line fi)) ;where is the while condition?
    (write-line FO "open" (strcat "c:\\my documents\\" new-line ".dwg")) ;; xxx is dwg name. What do you mean by xxx? Is xxx the same as new-line?
    ;This is where I would need to paste each unique script file I think, there was no code here. Each .scr file is very long (1000 +- rows). something like (paste new-line), but I need the text within the .scr file
    (write-line FO  " _-view front") 
    (write-line FO  "zoom extents") 
    (write-line FO  "Saveas new_line" )
    (write-line FO   "Close Y") ;;Close file, repeat for next entry note "Y"
    );end while loop
    (close fo)
    (close fi)
    (command "script" "mydwgfiles") ;should this be "mydwgfiles.scr" ?
    Forgive me for not following, but I am a beginner so very clear and thorough commenting goes a long way for me. Thanks

  4. #4
    Luminous Being
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    5,458

    Default

    Ok read post again, ignoring questions for moment.

    Create 100 lisp defuns in 1 big lisp in other words rewrite your scripts to lisp

    Then your action would be (load "mastertrees") typed on keyboard then load script "updatetrees" would become as next you can have as many defuns as you like.
    Code:
    ;mastertrees
    (defun tree01 ()
    .. do something here
    )
    (defun tree02 ()
    ... do something different
    )
    .. and so on
    Code:
    open dwg1 (tree02) (tree04) close y
    open dwg33 (tree045) (tree65) (tree47) close y
    I have a master library lisp for some software has around 50 defuns in it.

    Please post a sample of your script I think this will help to make more sense of what your trying to achieve.
    A man who never made mistakes never made anything

  5. #5
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Nov 2011
    Posts
    4

    Default SCR files

    Registered forum members do not see this ad.

    BigAl,
    I think I get what you are saying, I've posted two scripts below. I'm not sure how much it matters, but each dfun will be very long hence possibly slow. I will need to have the open and close statement after each dfun. to create a separate file for each. Is it also possible to call the dfuns and file names from lists, then just run a loop for the length of the list?

    Here are two of the scripts, if you run them any object snapping must be turned off.
    Boa_2006AutoCadScript.scrCampfire_2006AutoCadScript.scr

Similar Threads

  1. Opening multiple files in AutoCAD???
    By Honda Matt in forum AutoCAD General
    Replies: 5
    Last Post: 20th Nov 2012, 03:02 pm
  2. Replies: 1
    Last Post: 8th Nov 2010, 03:53 pm
  3. Changing NTF files to DWF files, Can you download the NTF AutoCAD add on?
    By BenGoble in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 1st May 2010, 02:44 pm
  4. Image Files and Rotation of AutoCAD Files
    By Michigan Engineer in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 25th May 2006, 08:28 pm
  5. How do I convert .dwg files to .plt files in Autocad 2000?
    By DPATTERSON23 in forum AutoCAD General
    Replies: 2
    Last Post: 21st Jan 2006, 08:01 pm

Bookmarks

Posting Permissions

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