Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Windows: improving on interaction of external text editors and Stata


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Windows: improving on interaction of external text editors and Stata
Date   Wed, 14 Jul 2004 16:38:44 -0700 (PDT)

On June 23, Dimitriy Masterov sent an AutoIt script to Statalist that
allows the execution of a do-file from an external text editor. On
June 27, Eva Poen distributed a script that allows the execution of
selected lines from a do-file.

I have modified Eva's script in a way that greatly increases its
speed. This was accomplished by sending the commands as one block to
the do-file editor instead of as individual lines to the command
window. A further advantage of this approach is that it is not
necessary to strip the Stata commands of comments, delimiters or
other characters that are not allowed in the command window. Stata
will now also stop when it encounters an error, which is not the case
when individual lines are sent to the command window.

Many thanks to Dimitriy and Eva for their scripts. With their help it
has become possible to fully integrate Stata with an external text
editor. Stata users can create a shortcut in their preferred editor
that calls the compiled AutoIt script and sends the selected commands
from the editor directly to Stata.

I hope that some list members will find this script useful and would
welcome any suggestions for improvement.

Friedrich Huebler

========== Start of script ==========
; AutoIt v3 script to run Stata commands from an external text
editor.
; Friedrich Huebler ([email protected]), 14 July 2004.
; Adapted from an AutoIt script by Eva Poen ([email protected]),
; sent to Statalist on 27 June 2004
; (http://www.stata.com/statalist/archive/2004-06/msg00807.html).
; AutoIt is available at http://www.autoitscript.com/autoit3/.

; NOTE: The title of the Stata window ("Intercooled Stata 8.2"), the
; title of the Do-file Editor window ("Stata Do-file Editor") and the
; path of the Stata executable ("C:/Stata8/wstata.exe") may have to
be
; modified before the script is compiled.

; Reduce SendKeyDelay and WinWaitDelay to speed up script
Opt("SendKeyDelay", 1)
Opt("WinWaitDelay", 100)

; Make backup of clipboard content
$clipboard = ClipGet()

; Copy selected line(s) from editor to clipboard
Send("^c")
$commands = ClipGet()

; Check if Stata is already open
If WinExists("Intercooled Stata 8.2") Then
  WinWait("Intercooled Stata 8.2")
  WinActivate("Intercooled Stata 8.2")
  ; Check if Do-file Editor is already open
  If WinExists("Stata Do-file Editor") Then
    WinWait("Stata Do-file Editor")
    WinActivate("Stata Do-file Editor")
    ; Make backup of text in Do-file Editor
    Send("^a" & "^x")
    $doeditor = ClipGet()
    ; Send commands to Do-file Editor and execute
    ClipPut($commands)
    Send("^v" & "^d")
    ; Restore text in Do-file Editor
    Send("^8")
    ClipPut($doeditor)
    Send("^a" & "^v")
    ; Activate main Stata window
    WinActivate("Intercooled Stata 8.2")
  Else
    ; Send commands to Do-file Editor and execute
    Send("^8")
    WinWait("Stata Do-file Editor")
    WinActivate("Stata Do-file Editor")
    ClipPut($commands)
    Send("^v" & "^d")
    ; Close Do-file Editor
    Send("^8" & "!{F4}")
    WinWait("Save changes")
    WinActivate("Save changes")
    Send("!d")
  EndIf
Else
  ; Run Stata
  Run("C:/Stata8/wstata.exe")
  WinWait("Intercooled Stata 8.2")
  WinActivate("Intercooled Stata 8.2")
  ; Send commands to Do-file Editor and execute
  Send("^8")
  WinWait("Stata Do-file Editor")
  WinActivate("Stata Do-file Editor")
  ClipPut($commands)
  Send("^v" & "^d")
  ; Close Do-file Editor
  Send("^8" & "!{F4}")
  WinWait("Save changes")
  WinActivate("Save changes")
  Send("!d")
EndIf

; Restore clipboard
ClipPut($clipboard)
========== End of script ==========



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index