I have been working with the fantastic UIA libraries by Descolada, but I have an issue. The thing is, it is too slow. I have been trying for hours to use caching but it's not very documented (or I am dumb, as I have been reading all wikis and examples)...
If someone could help me point out what I am doing wrong...
The script basically gets the clipboard, and uses UIA to paste it in certain window elements of the translation application Trados Studio. It pastes the clipboard on one field, then checks a button is on/off, toggles it if necessary and then inserts the clipboard on a different field.
This script takes between 5 and 7 seconds to execute which is too long. The fields are unchangind, so caching should be a good idea here (if I understand correctly what it does)
I changed the script to have it check whether UIA_interface was already in memory, but time savings are not noticeable, perhaps loading UIA:=UI_Interface() is not where the time goes. But I guess it does not hurt.
I tried to use, instead of the relevant lines of the original script, the following lines:
if not UIA {
UIA := UIA_Interface() ; Initialize UIA interface ; Parece más rápido que new UIA_Browser
cacheRequest := UIA.CreateCacheRequest()
cacheRequest.TreeScope := 5 ; Set TreeScope to include the starting element and all descendants as well
cacheRequest.AddProperty("ControlType")
cacheRequest.AddProperty("LocalizedControlType")
cacheRequest.AddProperty("AutomationId")
cacheRequest.AddProperty("Name")
cacheRequest.AddProperty("Value")
cacheRequest.AddPattern("Toggle")
}
without really knowing what they do, but those are the properties and patterns that my script uses so I guess this should be the way to go.
and then
npEl:= UIA.ElementFromHandleBuildCache(WinExist(ahk_exe SDLTradosStudio.exe), cacheRequest)
instead of
npEl := UIA.ElementFromHandle(WinExist(ahk_exe SDLTradosStudio.exe))
but this modification does nothing. It does not search any element, does not paste anything. So I don't know what I am doing wrong, to be honest. Documentation and examples do not seem to indicate how to perform searched with FindFirstBy in cached elements. So I have no idea what to do or how to speed up this script.
Any ideas?
Code: Select all
F3:: ; Búsqueda de Concordancia en Trados o, si no está abierto, en Kantan
StartTime:= A_TickCount
ClipBoard:=""
SendInput, {ControlDown}c{ControlUp}
ClipWait, .1
If WinExist("SDL Trados Studio") ; ESTÁ ABIERTA UNA INSTANCIA DE TRADOS ASÍ QUE HACE CONCORDANCE SEARCH EN TRADOS
{
Winactivate, SDL Trados Studio
if not UIA
UIA := UIA_Interface() ; Initialize UIA interface ; Parece más rápido que new UIA_Browser
WinWaitActive, ahk_exe SDLTradosStudio.exe
npEl := UIA.ElementFromHandle(WinExist(ahk_exe SDLTradosStudio.exe)) ; Get the element for the Trados window
npEl.FindFirstBy("AutomationID=[Editor] Edit Area").SetValue(Clipboard) ; Copia el clipboard en Concordance Search
Sleep, 100
SendInput, {Enter}
Boton:=npEl.FindFirstBy("ControlType=Button AND Name=Fuzzy Search") ; Busca si el botón Fuzzy Search en Termbase Search está desactivado. Si no, lo activa
TogglePattern:=Boton.TogglePattern
If TogglePattern.ToggleState=0 ; El botón está desactivado
TogglePattern.Toggle() ; Lo activa
npEl.FindFirstBy("ControlType=Edit AND LocalizedControlType=editar AND Name=").SetValue(Clipboard) ; Copia el clipboard en Termbase Search
SendInput, {Enter}
Sleep, 500
Desplazamiento := npEl.FindFirstBy("ControlType=Tree AND AutomationId=_TreeHits") ; La barrita de desplazamiento, el árbol en realidad de Termbase Search
scrollPattern := Desplazamiento.ScrollPattern
Loop, 10
scrollPattern.Scroll(, UIA.ScrollAmount_LargeIncrement) ; Llevo la barra de desplazamiento 10 páginas hacia abajo
}
EndTime := A_TickCount
ElapsedSeconds := (EndTime - StartTime)/1000.0
Msgbox, the msgbox was on the screen for %ElapsedSeconds% Seconds before you closed it.
Return