Jump to content

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


northcoastrat

Recommended Posts

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

 

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

Link to comment
Share on other sites

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.

 

;;; 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")

)

Link to comment
Share on other sites

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.

 

(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

Link to comment
Share on other sites

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.

;mastertrees
(defun tree01 ()
.. do something here
)
(defun tree02 ()
... do something different
)
.. and so on 

 

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.

Link to comment
Share on other sites

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.

Campfire_2006AutoCadScript.scr

Boa_2006AutoCadScript.scr

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...