Jump to content
JPlanera

BREAKTHROUGH??? Batch processing with user input!

Recommended Posts

JPlanera

I needed to print 200+ drawings located in multiple locations, but only a section of each drawing that was not previously defined by a view or common coordinates... A batch printing process that could pause at each drawing to accept user input was what i was after. I stumbled upon a bundle of code that works! As a novice coder, I am hoping someone out there will tell me there is a much easier way!

 

In order for this to work, I had to break in to a script file for user input. Since this cant be done, I created 2 seperate scripts within 2 LISPS that would loop infinitely.. I had to creat a txt file containing every drawing to be opened. This was done in excell fairly easily. The purpose of this list is to "read-line" and write to a script file. The script file would then contain one line. "OPEN" "file" "custom command" hopefully it makes sense as I post the code. The master list had to be modified everytime so that the first line is always "next" so I used VBA to delete the first line. This was all done with SDI=1 so i didnt have to worry about coding in a close..

 

Ok, here goes nothin...

 

SET SDI=1

Main start program. The first drawing must be open at this time, and the master list will contain drawings 2 on.

;BATCH PRINT USER DEFINED VIEW
;JPLANERA 7/3/12
;This routine will allow the user to define the view and will print the stored view
;Then the script callout starts the process that alters the "open" file script.
;Open the first drawing in the master list and initiate the DVP command to start.
;The master list will contain ALL but the current open drawing.
(DEFUN C:DVP ()
  (command "-view" "W" "1" pause pause)
  (while 
     (= 1 
        (getvar "cmdactive")
     )
    (command pause)
  )
  (command "-plot" "y" "model" "RICOH C5000 ENG" "Letter (8.5\" X 11\")" "i" "P" "n" "V" "1" "f" "c" "y" "monochrome.ctb" "y" "a" "n" "y" "y")
  (command "script" "U:\\batchpress\\mos.scr")
)

 

Contents of mos.scr

-VIEW
RESTORE
1
QSAVE
MOS

 

MOS.LSP this is the routine that reads from the master list, writes to a script file and erases the first line of the master list...

;OPEN DRAWING SCRIPT MODIFY
;JPLANERA 7/3/12
;This routine will read the first line of the "master" list of drawings, then write it to a script file.
;This script file will contain only 1 line of code so autocad does not get "confused"
;A VBA routine is then used to delete the first line of the master list so that when
;this routine is run again, the first line to be read is the "next" drawing in the list.
(defun c:MOS (/ MPTL L1 OF)
 (setq MPTL (open "U:\\batchpress\\masterpresstoollist.txt" "r")
)
 (setq L1 (read-line MPTL)
)
 (close MPTL)
 (setq OF (open "U:\\batchpress\\openfile.scr" "w")
)
 (write-line L1 OF)
 (close OF)
 (startapp "wscript" "\"U:\\batchpress\\deleteline.vbs\"")
 (princ)
 (command "script" "U:\\batchpress\\openfile.scr")
)

 

 

contents of master list txt file (shortened of course). Done in excell. "DVP" at the end starts the loop back to the first LISP routine.

OPEN M:\ENGR\Drawings\TOOLING\T18516\T18516.dwg DVP
OPEN M:\ENGR\Drawings\TOOLING\T18519\T18519.dwg DVP
OPEN M:\ENGR\Drawings\TOOLING\T18530\T18530.dwg DVP

 

 

contents of script file to open drawings and call back first command LISP. I tried to do this all in the master list but kept getting runtime errors. I suspect because the list was being used while I was trying to edit it... solution was two files.

OPEN M:\ENGR\Drawings\TOOLING\T18515\T18515.dwg DVP

 

 

DeleteLine Function by TomRiddle 2008

DeleteLine "U:\BATCHPRESS\masterpresstoollist.txt", "", 1, 0 

Function DeleteLine(strFile, strKey, LineNumber, CheckCase) 
'DeleteLine Function by TomRiddle 2008 
'Remove line(s) containing text (strKey) from text file (strFile) 
'or 
'Remove line number from text file (strFile) 
'or 
'Remove line number if containing text (strKey) from text file (strFile) 
'Use strFile = "c:\file.txt"  (Full path to text file) 
'Use strKey = "John Doe"      (Lines containing this text string to be deleted) 
'Use strKey = ""              (To not use keyword search) 
'Use LineNumber = "1"         (Enter specific line number to delete) 
'Use LineNumber = "0"         (To ignore line numbers) 
'Use CheckCase = "1"          (For case sensitive search ) 
'Use CheckCase = "0"          (To ignore upper/lower case characters) 

   Const ForReading=1:Const ForWriting=2 
   Dim objFSO,objFile,Count,strLine,strLineCase,strNewFile 
   Set objFSO=CreateObject("Scripting.FileSystemObject") 
   Set objFile=objFSO.OpenTextFile(strFile,ForReading) 
   Do Until objFile.AtEndOfStream 
      strLine=objFile.Readline 
      If CheckCase=0 then strLineCase=ucase(strLine):strKey=ucase(strKey) 
      If LineNumber=objFile.Line-1 or LineNumber=0 then 
         If instr(strLine,strKey) or instr(strLineCase,strkey) or strKey="" then 
            strNewFile=strNewFile 
         Else 
            strNewFile=strNewFile&strLine&vbcrlf 
         End If 
      Else 
         strNewFile=strNewFile&strLine&vbcrlf 
      End If 
   Loop 
   objFile.Close 
   Set objFSO=CreateObject("Scripting.FileSystemObject") 
   Set objFile=objFSO.OpenTextFile(strFile,ForWriting)  
   objFile.Write strNewFile  
   objFile.Close  
End Function 
 

 

Ok hopefully this all makes sense. If further explaing is needed please let me know. Also i would be happy to hear there is an easier way!! Im sure this could be used to do multiple user input commands but i think i am going to take a break before I try to do any more!

Share this post


Link to post
Share on other sites
Dadgad

Sounds like you deserve a little vacation, why not consider a bried virtual trip to ..... http://www.lee-mac.com/programs.html#general.

 

There is a better than even chance that you will find something there to help you.

 

As for stopping and resuming a script, you might want to read this..... http://www.lukewarmcoffee.com/cad/AUGI%20-%20Passionate%20Scripting%20for%20Everyone.pdf

 

Hope you find some help in those links.

Share this post


Link to post
Share on other sites
BIGAL

Why not just write one big script with every dwg name in it created from the master todo list a script can have hundreds of open dwgs in it make sure close at end, just for practical sense write 1 line for each dwg. I think your over complicating it. Your dwg list can have multiple choice like,

dwg1name view1name

dwg1name view2name

dwg2name viewname

dwg3name viewname

 

open dwg1 -VIEW RESTORE 1 dvp close N
open dwg2 -VIEW RESTORE 1 dvp close N
open dwg3 -VIEW RESTORE 1 dvp close N

Share this post


Link to post
Share on other sites
JPlanera
Why not just write one big script with every dwg name in it created from the master todo list a script can have hundreds of open dwgs in it make sure close at end, just for practical sense write 1 line for each dwg. I think your over complicating it. Your dwg list can have multiple choice like,

dwg1name view1name

dwg1name view2name

dwg2name viewname

dwg3name viewname

 

open dwg1 -VIEW RESTORE 1 dvp close N
open dwg2 -VIEW RESTORE 1 dvp close N
open dwg3 -VIEW RESTORE 1 dvp close N

 

I did try something similar to this, but the script would not resume, unless of course i did something wrong, which is a great possibility.

Share this post


Link to post
Share on other sites
JPlanera
Sounds like you deserve a little vacation, why not consider a bried virtual trip to ..... http://www.lee-mac.com/programs.html#general.

 

There is a better than even chance that you will find something there to help you.

 

As for stopping and resuming a script, you might want to read this..... http://www.lukewarmcoffee.com/cad/AUGI%20-%20Passionate%20Scripting%20for%20Everyone.pdf

 

Hope you find some help in those links.

 

Thank you! As BIGAL said, I definitely think I am over complicating it. I am very green at this stuff and have not had any training, and this was the only (or first) thing I could come up with. I searched the forums and asked around, but noone had a solution to my question... I will check out the links and see what i can dig up. If (or when...) I find something, I will report back with an update. Thank you for the input guys! If LeeMac stumbles on to this I am sure he will have something to say. HA

Share this post


Link to post
Share on other sites
JPlanera

Ok.. This is what I found out:

 

I did not see anything that would help on Lees page.. But the lukewarmcoffe link had some nice info.

 

The RESUME command worked once the script crashes, but you have to type the command in every drawing. It simplifies the code, but requires extra keystrokes.

 

It looks like script-hopping is the answer and it appears that this is what i did. The only problem is, it works on 1 drawing only. In order to get the "batch" process to work, one script would have to go to the next line everytime, which is impossible, right?? That is where the VBA came in to remove the processed drawing from the master list and the LISP to write-line to a SCR file.. It may seem overly complicated but I couldnt glean any easier procedure. Please if someone can enlighten me I would appreciate it!

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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