Jump to content

Recommended Posts

Posted

Hi,

 

I got a routine off the net that lets me alter multiple drawings with a lisp routine i create. It does this by creating a script file and opening each drawing one at a time then applying the lisp routine.

 

This is limited however as the lisp routine can not take any user input and must be hard-wired to carry out amendments.

 

Is it possible to create a vlisp routine that can take user input in one drawing and apply it to a selection of drawings?

 

Thanks

Posted

hi nauggie,

can you post the routine on here?

Posted

The original can be found here:

 

http://www.jefferypsanders.com/autolisp_batchlisp.html

 

I had to amend it because my file directories were to long for the script to handle. My amended one is below. (you need a selection lisp which you get in the link)

 

(defun C:BATCHLISP()

 ;;;--- Set a flag for unsuccessful script creation
 (setq gogo nil)

 ;;;--- Set a flag for a change in the SDI system variable
 (setq oldSDI nil)
 (setq filedia nil)
   
 (command ".QSAVE")

 ;;;--- If the SELECTFILES routine is found...
 (if(load "selectfiles")
   (progn

     ;;;--- Let the user select the drawing files
     (if(setq files(selectfiles (getvar "dwgprefix") "*.dwg" 0))
       (progn

         ;;;--- Let the user select the AutoLisp program
         (if(setq lispFile(getfiled "Select AutoLisp File" "" "LSP" )
           (progn

             ;;;--- Check the slashes in the file name to make sure they are correct
             (repeat 10(setq lispFile(vl-string-subst "/" "\\" lispFile)))

             ;;;--- Open the script file to write
             (if(setq fil(open "BATCHLISP.SCR" "w"))
               (progn

                 ;;;--- Save the SDI setting [single Document Interface]
                 (setq oldSDI (getvar "sdi"))
         (setq filedia (getvar "filedia"))
                 
                 ;;;--- Set the SDI system variable to 1 [single Document Mode]
                 (setvar "sdi" 1)
                
                 ;;;--- Send the command to turn the file dialog switch off to the script file
                 (princ (strcat "(setvar " (chr 34) "filedia" (chr 34) " 0)" ) fil)

                 ;;;--- Cycle through each drawing file
                 (foreach a files

                   ;;;--- Send the open command to the script file
                   (princ (strcat "(command " (chr 34) ".open" (chr 34) " ")fil)
                   (prin1 a fil)
                   (princ ")" fil)
                 

                   ;;;--- Send the LOAD command to the script file
                   (princ (strcat "\n(load " (chr 34)) fil)
                   (princ lispFile fil)
                   (princ (strcat (chr 34) ")" ) fil)
                   (princ "\n" fil)
                   (princ (vl-filename-base lispFile) fil)

                   ;;;--- Send the SAVE command to the script file
                   (princ "\n.QSAVE" fil)
                   (princ "\n" fil)

                   ;;;--- Reset the FILEDIA before opening the next drawing
                   (princ (strcat "\n(setvar " (chr 34) "filedia" (chr 34) " 0)" ) fil)
                 )
                 
                 ;;;--- Finish the script file
                 (princ "\n" fil)

                 ;;;--- If SDI [single Document Interface] was changed...
                 (if oldSDI

                   ;;;--- Set it back to it's original state before ending
                   (princ (strcat "\n(setvar " (chr 34) "sdi" (chr 34) " " (itoa oldSDI)")\n") fil)
                 )
         
           (if filedia

                   ;;;--- Set it back to it's original state before ending
                   (princ (strcat "\n(setvar " (chr 34) "filedia" (chr 34) " " (itoa filedia)")\n") fil)
                 )

         
                 ;;;--- Close the script file
                 (close fil)

                 ;;;--- Set the flag for successful script creation
                 (setq gogo T)

               )
               (alert "Could not open BATCHLISP.SCR to write.\nCheck your rights to the default directory.\n\nProgram Aborting!")
             )           
           )
           (alert "No AutoLisp program selected.\n\nProgram Aborting!")
         )  
       )
       (alert "No files selected.\n\nProgram Aborting!")
     )
   )
   ;;;--- Else the SELECTFILES routine was not found.
   (alert "This program requires the SELECTFILES routine\ncreated by JefferyPSanders.com.\n\nProgram Aborting!")
 )

 ;;;--- If the script file was created successfully...
 (if gogo
   (progn

     ;;;--- Alert the user
     (alert "\nScript file created successfully!\n Press okay to start.")

     ;;;--- Start the script file
     (command "script" "BATCHLISP.scr")

   )
 )
 (princ)
)

  • 2 years later...
Posted

Yummy,

 

Just the routine that I needed.

 

Thank you for the link to the original as well as the improved version dealing with longer file directory paths.

  • 1 month later...
Posted

I tried to run this batchlisp but it doesn;t work, Im using autocadd 2007. hOW to link the selection files and which directory where i can save ithe selectfile.dcl.

Posted

Try this. I wrote it some time ago so it's by no means as pretty or clean as something I could write today.. in fact, I have been meaning to update it and some day I will. As it stands however, it works like a champ. It's tried and true, and people use this (or it's older brother, since this is the 'stripped down' version) on a daily basis.

 

Usage is fairly simple. Create an option in the beginning COND (in the 'printsettings' function) to check input. This is just a place you can check your selection to see if it's valid. In the (dostuff) function is where you actually.. well.. do stuff. Just create a new option in the COND there (yes, for each new setting you have to create a new item in two different condition statements.. like I said, I wrote this a long time ago) and you're good to go. If you want to run a particular LISP, just to the (load "whatever.lsp")(c:whatever) trick. That's probably the easiest way, though you could also create functions right there. Note that the function MUST return nil. Also, it would be nice if your drawings didn't ask for shape files or macros or whatever when you open them. That might cause a hiccup.

 

For a particular directory, yes it is text based. I don't know anything about DCL yet, though I am stripping this down with the intent to improve it. Just follow the instructions at the prompt. You can copy and paste a directory from a Microsoft Explorer window, just be sure to open with a quote " and end with a quote ", that is to say,

 

"drive:\directory 1\directory 2"

 

Note the lack of a backslash at the end; this is how Windows has it, you can copy and paste directly. You can also specify the search pattern and the number of subdirectories to look into. Once you select both of those (note that you do NOT need to select a directory; if you don't, it'll just run on the .dwg you currently have open), you can continue on and select the tabs you want to apply it to.

 

I hope this helps. I know it's not the prettiest solution, I'm sure Lee will come up with something just as good that's only 5 lines long, but I plan on cleaning it up soon, and it does work.

Blitz.LSP

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