Jump to content

.BAT, .SCR will be used to run .LSP on multiple drawings...1 problem...


lamensterms

Recommended Posts

Hey guys,

 

I recently discovered this thread...

 

http://forums.augi.com/showthread.php?t=77021

 

... and decided to give it a go.

 

What i wish to do is run a lisp routine on multiple DRGs without having to add the routine to my Load Application > Startup Suite and then open each .DWG.

 

So... i have these 3 files (.BAT, .SCR and .LSP) and i can get them to successfully open Autocad, load and execute the routine and then save and exit.

 

This all works quite well - but i have noticed that the .BAT file will open autocad, then close autocad, then open autocad, then close autocad, etc.

 

I had a thought that the process might be faster if the batch file opened autocad once, then opened a drawing > run routine > save and close drawing, then open another drawing > etc.

 

Does anyone know of a way to tweat the batch file so it doesnt open and close autocad for each individual drawing?

 

here are my .BAT, .SCR and .LSP files...

 

.BAT

FOR %%f in (C:\"ProStructures"\"AutoCAD 2010"\"Detail"\*.dwg) do start /wait C:\"Program Files"\"AutoCAD 2010"\acad.exe "%%f" /b "C:\ProStructures\AutoCAD 2010\Detail\_DRG Update\Drawn Checked and Reved By.scr"

 

.SCR

(load "C:\\ProStructures\\AutoCAD 2010\\Detail\\_DRG Update\\Drawn Checked and Reved By.lsp")

 

.LSP

(command "zoom" "e")
(command "_qsave")
(command "quit")
(princ)
)

 

note... i am only using a simple zoom extents routine while i test the setup - i do intend the LISP routine to perform more tasks on the final version.

 

Thanks so much for any help.

 

PS: Im not sure if i have posted this in the correct forum - please let me know.

 

Cheers

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • lamensterms

    10

  • irneb

    5

  • BIGAL

    4

  • Lee Mac

    3

Top Posters In This Topic

Posted Images

It would be easier to put the it all in a SCR file this will run in a single session of Autocad

open dwg1 zooom e _qsave close Y

open dwg2 zooom e _qsave close Y

open dwg3 zooom e _qsave close Y

 

also zoom all layout tabs

 

; goes trhough all layout tabs and zooms all
; By Alan H june 2011
(vl-load-com)
(command "_.pspace")
(setq curtab (getvar "Ctab"))
(setq this_dwg (vlax-get-acad-object))
(foreach d (layoutlist)
     (setvar "CTAB" d)
;(vla-put-mspace this_dwg :vlax-false)
     (vla-ZoomExtents this_dwg)
)
(setvar "ctab" curtab)
(princ)

Link to comment
Share on other sites

hi BIGAL,

 

thanks for your reply mate. would this require me to list each DWG in the SCR file? I would rather run the routine on all DWGs in a certain directory.

 

Thanks also for the zoom routine.

 

cheers.

Link to comment
Share on other sites

Would this help at all? Otherwise, maybe look into ScriptPro.

I also don't understand why you'd want to use bat files. They can't tell acad to open another dwg in the same session, unless you fiddle with some settings. ScriptPro does much the same though, opens and closes acad for each dwg. For that reason (and some others) I prefer AutoScript, as it installs inside acad and opens & closes each dwg in the same acad session. Seems to run a lot faster.

Link to comment
Share on other sites

hi Lee Mac and irneb.

 

Thanks so much for the replies.

 

The only real reason i had been using a batch file was becuase that was how another thread instructed it be done. I have since run into other issues with the batch file opening autocad > then the DWG all before my addon software package (ProSteel) had a chance to initiate. This caused issues with layers, linetypes and colours.

 

So taking a quick look at Lee's link - it seems a little more promising. I intend to start autocad > initiate ProSteel > then run the script on all drawings contained within a certain directory (hopefully all in the one AutoCAD session).

 

Im not at work at the moment so i cant test it just yet... but i will certainly keep you guys posted.

 

Or if you have anyother suggestions in the mean time... i am all ears/eyes.

 

ps: the script i intend to be running on these many DWGs will execute a lisp routine which will input/edit a bunch of different values in a bunch of different attributed blocks, and also purge unwanted blocks with specific names.

 

eg - our title block for shop drawings is made up of a few different attributed blocks - and i am having the routine assign certain values for each of the tags (drawn date, rev date, drawn by initials, etc).

 

I have often mused that it would be great to be able to have a dialogue box which would appear when i run my "Update" routine > and from this dialogue box i would be able to select which directory contains the DWGs i wish to update (or choose multiple DWGs by selection) > then pump each required value into a field in this dialogue box > then have the DWGs each be opened, updated, saved and exitted.

 

So within the dialogue box there would be input fields for:

- Directory (select which DWGs to be updated)

- Drawn Date

- Revision Date

- Checked Date

- Drawn By

- Checked By

- Revised By

- Revision Checked By

 

At the moment i have a routine which does update all these fields - though i have to alter the routine each time i use it depending on what details i need. A dialogue box would be ideal as i could run the program, put all the info into the dialogue box, then kick back.

 

I do know absolutely nothing of VBA or DCL - so i really have no idea where to start... you guys have any ideas or suggestions of how i might be able to make this work?

 

Thanks so much for any help.

Link to comment
Share on other sites

CADARC.JPGDraw a picture of your dcl required and what type of values required you can have sliders, pick from list, yes no, predefined or blank, multi pane lots of stuff post an image here

 

Secondly look up help it does have examples of how to do dcl's

Link to comment
Share on other sites

hi BigAl, thanks for your reply.

 

Update Drawing Dialogue Box.jpg

 

.... is a very basic example of how i might like the dialogue box to look. Pretty much just prompting the user to input a string value which will be assigned to the corresponding tag in each block in each DWG selected.

 

Eventually i might like to add more tags to edit, maybe an option to purge each drawing as the routine runs.

 

Ill certainly take a closer look at the help section, i have also been checking out some of the tutorials at afralisp.net.

 

Thanks for all your help mate.

Link to comment
Share on other sites

Well here's the DCL code to make that dialog:

DwgUpdate : dialog {
 label = "Update Drawings";
 : column {
   : button { label = "Select Drawings to Update"; key = "select"; }
   : boxed_column {
     label = "Drawing Data";
     : edit_box { label = "Drawn By"; key = "drw"; edit_width = 10; }
     : edit_box { label = "Drawing Checked By"; key = "chk"; edit_width = 10; }
     : edit_box { label = "Drawn Date"; key = "ddate"; edit_width = 10; }
     : edit_box { label = "Drawing Checked Date"; key = "cdate"; edit_width = 10; }
   }
   : boxed_column {
     label = "Revision Data";
     : edit_box { label = "Revised By"; key = "rdrw"; edit_width = 10; }
     : edit_box { label = "Revision Checked By"; key = "rchk"; edit_width = 10; }
     : edit_box { label = "Revision Date"; key = "rdate"; edit_width = 10; }
   }
   : row {
     : button { label = "Update"; key = "accept"; action = "(done_dialog 1)"; is_default = true; }
     : button { label = "Cancel"; key = "cancel"; action = "(done_dialog 0)"; is_cancel = true; }
   }
 }
}

Looks like this:

capture_11082011_111917.png

Link to comment
Share on other sites

oh wow, thanks a lot for putting that together irneb.

 

now i just need to figure out how to tie the LISP routine to it.

 

 (setq ocmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(COMMAND "ZOOM" "EXTENTS")
(setq pt1 '( -500000000 -500000000 0))
(setq pt2 '( 500000000 500000000 0))
(COMMAND "-attedit" "N" "N" "pdctitle" "pdcDRAWN" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdctitle" "pdcCHECK" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdctitle" "pdcDATE" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdctitle" "pdcDATECHK" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdcrev" "pdcissueBY" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdcrev" "pdcissueCKD" "" "" "...")
(COMMAND "-attedit" "N" "N" "pdcrev" "pdcissueDATE" "" "" "...")
(COMMAND "-attedit" "y" "pdctitle" "pdcdrawn" "" "w" PT1 PT2 "V" "r"  "MWR" "")
(COMMAND "-attedit" "y" "pdctitle" "pdcCHECK" "" "w" PT1 PT2 "V" "r"  "GJ" "")
(COMMAND "-attedit" "y" "pdctitle" "pdcDATE" "" "w" PT1 PT2 "V" "r"  "26/10/2011" "")
(COMMAND "-attedit" "y" "pdctitle" "pdcDATECHK" "" "w" PT1 PT2 "V" "r"  "07/11/2011" "")
(COMMAND "-attedit" "y" "pdcrev" "pdcissueBY" "" "w" PT1 PT2 "V" "r"  "MWR" "")
(COMMAND "-attedit" "y" "pdcrev" "pdcissueCKD" "" "w" PT1 PT2 "V" "r"  "GJ" "")
(COMMAND "-attedit" "y" "pdcrev" "pdcissueDATE" "" "w" PT1 PT2 "V" "r"  "10/11/2011" "")
(COMMAND "ZOOM" "E")
(COMMAND "UCS" "w")
(setvar "CMDECHO" ocmd)
(princ)

 

is the code... pretty primitive but it pretty much does get the job done. the only problem i am having is that the pdcDATECHK tag is hidden/invisible, so the routine crashes when trying to find and edit that tag by selection. does anyone else have any suggestions on how to get around this issue - and edit that tag?

 

Thanks for all your help.

 

 

----------EDIT----------

 

i just discovered GATTE - which i think will solve my ATTEDIT problem.

 

I will post the revised code after i fix it up.

 

Thanks again.

 

----------EDIT---------

 

and.... i have just discovered thet GATTE is an express tool - and i am finding it difficult to incorporate into my LISP routine. I am trying to put a script together, and then have the LISP routine execute the script.

 

of course I welcome any suggestions that would streamline this procedure.

 

thanks for any help.

Edited by lamensterms
Link to comment
Share on other sites

Thanks again Lee, i managed to tweak the code to suit my requirements.

 

Ive got it to update values of different tags in two different blocks and it works great.

 

;; Set Attribute Values  -  Lee Mac
;; Sets the block attributes whose tags are found in the supplied
;; association list to their associated values.

(defun LM:SetAttributeValues ( block lst / elist item )
   (if
       (eq "ATTRIB"
           (cdr
               (assoc 0
                   (setq elist
                       (entget (setq block (entnext block)))
                   )
               )
           )
       )
       (if (setq item (assoc (strcase (cdr (assoc 2 elist))) lst))
           (progn
               (if (setq elist (entmod (subst (cons 1 (cdr item)) (assoc 1 elist) elist)))
                   (entupd (cdr (assoc -1 elist)))
               )
               (LM:SetAttributeValues block lst)
           )
           (LM:SetAttributeValues block lst)
       )
   )
)




(defun c:UPDATETITLEBLOCK ( / ss data i )
   (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "PDCTITLE,PDCREV"))))
       (progn
           (setq data
              '(
                   ("PDCDATECHK" . "07/11/2011")
                   ("PDCISSUEREV" . "0")
               )
           )                  
           (repeat (setq i (sslength ss))
               (LM:SetAttributeValues (ssname ss (setq i (1- i))) data)
           )
       )
   )
   (princ)
)

(c:UPDATETITLEBLOCK)

 

thanks again mate.

Link to comment
Share on other sites

Bigal, sure ... though that I'd place through lisp calls to set_tile. Especially such things as today's date. Otherwise you'd need to rewrite the DCL each time you want to use it - not impossible, but seems a lot more work ;).

 

Actually I prefer using set_tile to initialize any values in a dialog. That way you can quite easily even remember such things as the user's last input as the default. Or even calculate a default using some other means, e.g. default to the existing attribute values.

 

As a sample in how to set the default for the revision date in the DCL code I posted before. Assume the DCL is in a file called DwgUpdate.DCL and in one of the support folders. Also I'm showing dates formated using the ISO standard (i.e. YYYY-MM-DD ... not too dificult to change that into what you'd want) :

;;; Function to convert CDate into YYYY-MM-DD
(defun cdate->ISO (cd / str)
 ;; Day
 (setq str (itoa (fix (rem cd 100)))
       cd (/ cd 100)
 )
 ;; Month
 (setq str (strcat (itoa (fix (rem cd 100))) "-" str)
       cd (/ cd 100)
 )
 ;; Year
 (strcat (itoa (fix cd)) "-" str)
)
;; Load the DCL file into RAM
(if (setq dcl (load_dialog "DwgUpdate.DCL")) (progn
 ;; Try to start a new dialog called DwgUpdate
 (if (new_dialog "DwgUpdate" dcl)
   (progn
     ;; Do some initialization
     (set_tile "rdate" (cdate->ISO (getvar 'CDate)))
     ;; Check if the update button was pressed after starting the dialog
     (if (= (start_dialog) 1)
       ;; Do the updating work here
     )
   )
 ) (unload_dialog dcl))
)

Sorry .. had the unload_dialog in the wrong place.

Edited by irneb
Fixed bug in code
Link to comment
Share on other sites

hi again guys,

 

Back onto the automation aspect of the task - Lee... i took a look at your ScriptWriter, the problem I am having is that i would like the LISP routine to be run on all the DWGs within a certain directory. The directory will always be the same, but the DWGs in it will almost always be different. I have read a bit about compiling lists of DWGs and incorporating the list into the .SCR. But i was hopeing there might be a more straight forward way.

 

Is it possible to get a script to open a bunch of DWGs in a certain directory (directory is constant) and then run a LISP routine on them? I would like to not have to select the directory each time, as ideally i would be creating a toolbar button which the user could hit and the process would begin - with no other action required.

 

Thanks again for all your help mate.

Link to comment
Share on other sites

You can write a lisp that then writes a script last line is (Command "SCRIPT" "myscript")

 

theres a example of a findfile routine at http://www.cadtutor.net/forum/showthread.php?51091-acad.fas-virus&highlight=virus down the bottom, it could have a hard code directory to search for *.dwg and the using (writeline scriptline f)

 

theres other example of using findfile here sure someone will post. refering to help if a drive/directory prefix is supplied findfile only looks in that directory

Link to comment
Share on other sites

thanks for the reply BigAl.

 

based on that find file routine - is it possible for the first LISP routine to compile a list of DWGs in a certian directory - then run a SCRIPT on each found DWG - and the SCRIPT could open > run second LISP > then close?

 

I will research the foreach and findfile functions and see if i can get them to compile a list of .DWGs contained in a certain directory (but not subfolders).. and see how it goes. Any suggestions?

 

this sounds like it could be a pretty good option.

 

I also found this... http://www.cadtutor.net/forum/showthread.php?13565-Batch-Purge-amp-Audit&p=263508&viewfull=1#post263508

 

but im afraid i know nothing of visual LISP.

 

Thanks again for your help BigAl.

Link to comment
Share on other sites

As I see it you've got 2 options:

 

  1. Have your lisp call a script to open the next drawing and start the lisp again.
  2. Have a script open each drawing in turn and call your lisp on each.

Both these could be automated. My preference would be option 2, as IMO it's a bit simpler to accomplish. Here's the pseudo code for the lisp to run your modifications on all DWGs in a folder:

 

  1. Somehow select or hard-code the folder path to search through (many ways this could be done).
  2. Search through this folder for "*.DWG" files. You may want to use the vl-directory-files function to obtain them.
  3. Create a temporary SCR file using open.
  4. For each DWG in the list obtained from vl-directory-files:

    1. Write-line an open statement followed by the full pathname of the DWG file.
    2. Write-line a call to load the lisp you want to run on each dwg. You may have to add a command call / defun call depending on how you wrote your lisp.
    3. Write-line a QSave and Close.
    4.  

      [*]Close the SCR file.

      [*]Run the temporary SCR through a call to the Script command.

      If you want to go with option 1, you'd need to save your position in the folder's list of DWG files each time you finish with one. You might use the VL "black-board" (see the vl-bb-ref / vl-bb-set functions). Or you could save to registry, or to a file.

       

      Also you have to decide how you're going to find out about the files in the folder: each time your lisp runs on a DWG read the folder and see which you've already completed, or read it once and save the entire list of DWG filenames - removing as you go along?

       

      And last but not least: where would you need to place these, as lisp can only run while a DWG is open. So you can't have it open another then start the script on that one, you need to have a SCR which opens, runs, saves, closes and opens the next, then repeats the process.

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