AutoIt application tips

Source: Internet
Author: User

We use AutoIt to implement a relatively complex operation, which uses many typical features. Here we will summarize them.

### Traverse a window

$ Var = WinList ("7-Zip file manager ")
For $ I = 1 to $ var [0] [0]
WinActivate ($ var [$ I] [0])
WinWaitActive ($ var [$ I] [0])
......
Next

WinList returns a two-dimensional array. $ var [0] [0] indicates the number of matched windows, and $ var [$ I] [0] indicates the window title, $ var [$ I] [1] is the window handle

### String Input

ClipPut ($ printdir)
Send ("^ v {Enter }")

Simple input can directly use Send () to simulate keyboard operations. For complex strings, you can use the clipboard function ClipPut

### File Traversal

$ Dwg_handle = FileFindFirstFile ("*. dwg ")
While 1
$ Dwg = FileFindNextFile ($ dwg_handle)
If @ error Then ExitLoop
......
WEnd

Traverse all. dwg files in the directory

### File read/write

$ Outfile = FileOpen ($ printfile, 2)
If $ outfile =-1 Then
MsgBox (0, "Error", "Unable to create file ")
Exit
EndIf

FileWriteLine ($ outfile, 'autocad 2000 Batch Plot List file ')

This part of the function is not particularly powerful, it provides a simple row read/write function. My task needs to write the information of each file to the list, and the total number of files starts with the list, so I had to call Notepad for search replacement, who makes Sed not included in windows.

The complete example is as follows. The script function is to traverse the 7zip window in the system, decompress the folder in the compressed package, and then extract. the dwg file is written to the print list in a certain format and opened with the AutoCAD batch print program. Open all. DOC files in Word,

Function: generate an AutoCAD batch printing list
; Author: rogerz. zhang
; Date: 2006.11.24

Opt ("WinWaitDelay", 100)
Opt ("WinTitleMatchMode", 2)
Opt ("WinDetectHiddenText", 1)
Opt ("MouseCoordMode", 0)

$ Printdir = "C: \ Documents ents and Settings \ public-proj \ Desktop \ Print"
$ Printfile = "C: \ Documents ents and Settings \ public-proj \ Desktop \ print. bp3"
$ Word = "c: \ Program Files \ Microsoft Office \ Office10 \ WinWord.exe"
$ St = '"C: \ Documents ents and Settings \ public-proj \ My Documents ents \ st. dwg | st "'
$ Count = 0

Unzip ()
CreateList ()
EditList ()
BatchPlot ()

Func Unzip ()
$ Var = WinList ("7-Zip file manager ")
For $ I = 1 to $ var [0] [0]
WinActivate ($ var [$ I] [0])
WinWaitActive ($ var [$ I] [0])
Send ("+ {NUMPADADD} {F5 }")
WinWaitActive ("copy ")
ClipPut ($ printdir)
Send ("^ v {Enter }")
WinWaitActive ($ var [$ I] [0])
Send ("! {F4 }")
Next
EndFunc

Func CreateList ()
$ Outfile = FileOpen ($ printfile, 2)
If $ outfile =-1 Then
MsgBox (0, "Error", "Unable to create file ")
Exit
EndIf
FileWriteLine ($ outfile, 'autocad 2000 Batch Plot List file ')
FileWriteLine ($ outfile, '"batch file name",' & $ printfile)
FileWriteLine ($ outfile, '"batch journal log on? ", # TRUE #')
FileWriteLine ($ outfile, '"batch journal log filename", "C: \ Program Files \ AutoCAD 2002 \ Support \ BatchPlt \ BPJOURNL. LOG "')
FileWriteLine ($ outfile, '"batch journal header ",""')
FileWriteLine ($ outfile, '"batch journal user comment ",""')
FileWriteLine ($ outfile, '"batch journal append? ", # FALSE #')
FileWriteLine ($ outfile, '"batch error log on? ", # TRUE #')
FileWriteLine ($ outfile, '"batch error log filename", "C: \ Program Files \ AutoCAD 2002 \ Support \ BatchPlt \ BPERROR. LOG "')
FileWriteLine ($ outfile, '"batch error header ",""')
FileWriteLine ($ outfile, '"batch error append? ", # FALSE #')
FileWriteLine ($ outfile, '"batch num files" ,__ COUNT __')
FileWriteLine ($ outfile, '"batch win size", "160,24 "')
FileChangeDir ($ printdir)
$ Dir_handle = FileFindFirstFile ("*.*")
If $ dir_handle =-1 Then
MsgBox (0, "Error", "No files/directories matched the search pattern ")
Exit
EndIf
While 1
$ Dir = FileFindNextFile ($ dir_handle)
If @ error Then ExitLoop
FileChangeDir ($ dir)
$ Dwg_handle = FileFindFirstFile ("*. dwg ")
$ Doc_handle = FileFindFirstFile ("*. doc ")
While 1
$ Dwg = FileFindNextFile ($ dwg_handle)
If @ error Then ExitLoop
$ Count = $ count + 1
FileWriteLine ($ outfile, '"DWG #' & $ count & 'filename", "'& @ WorkingDir &' \ '& $ dwg &'"')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'layout", "* current tab *"')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'plotsetup", '& $ st)
FileWriteLine ($ outfile, '"DWG #' & $ count & 'plotdevice", "default "')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'layers ",""')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'plotarea ",""')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'plotscale ",""')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'scalecustom", # FALSE #')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'scalelw", # FALSE #')
FileWriteLine ($ outfile, '"DWG #' & $ count & 'plotfile ",""')
WEnd
While 1
$ Doc = FileFindNextFile ($ doc_handle)
If @ error Then ExitLoop
; Run ($ word & '"' & @ WorkingDir & '\' & $ doc & '"/mFilePrintDefault', "", @ SW_HIDE)
Run ($ word & '"' & @ WorkingDir & '\' & $ doc ,"")
WEnd
FileChangeDir ("..")
FileClose ($ doc_handle)
FileClose ($ dwg_handle)
WEnd
FileClose ($ outfile)
FileClose ($ dir_handle)
EndFunc

Func EditList ()
Run ("notepad" & $ printfile)
If not WinActive ("print-Notepad") Then WinActivate ("print-Notepad ")
WinWaitActive ("print-Notepad ")
Send ("^ h ")
WinWaitActive ("replace ")
Send ("_ COUNT __{ tab }")
ClipPut ($ count)
Send ("^ v! A ")
Sleep (50)
Send ("{ESC }")
IF Not WinActive ("print-Notepad") Then WinActive ("print-Notepad ")
WinWaitActive ("print-Notepad ")
Send ("^ s ")
Sleep (50)
Send ("! {F4 }")
EndFunc

Func BatchPlot ()
If Not WinExists ("AutoCAD batch printing utility") Then
Run ("C: \ Program Files \ AutoCAD 2002 \ Support \ BatchPlt \ batchplt.exe ")
WinWaitActive ("autoscaling 2002 ")
WinWaitActive ("AutoCAD batch printing utility ")
EndIf
If Not WinActive ("AutoCAD batch printing utility") Then WinActivate ("AutoCAD batch printing utility ")
WinWaitActive ("AutoCAD batch printing utility ")
Send ("^ o ")
WinWaitActive ("opening the batch print list file ")
ClipPut ($ printfile)
Send ("^ v {Enter }")
EndFunc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.