![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Yay! Dance! Yay! :dance:](./images/smilies/dance.gif)
Code: Select all
GetDavinciElement() {
static davinciId, davinciElement
if (!(dvId := WinExist("ahk_exe davinci.exe")))
return
if ((davinciId == dvId) && davinciElement)
return davinciElement
davinciElement := "", davinciId := dvId
while (!davinciElement && WinExist("ahk_exe davinci.exe")) {
try davinciElement := UIA_Interface().ElementFromHandle(dvId)
}
return davinciElement
}
Code: Select all
if (!WinExist("ahk_exe davinci.exe"))
; DaVinci window doesn't exist, run it?
if !(dvEl := UIA.ElementFromHandle("ahk_exe davinci.exe"))
; DaVinci element wasn't returned - something went wrong? Window closed in the meanwhile?
; Otherwise the UIA element was found and is ready to be used
Code: Select all
if !(dvEl := GetDavinciElement())
; DaVinci window UIA element wasn't returned, which probably means that the window doesn't exist - run it?
; Element found, do stuff
To save Descolada some time I'll reply. It works for me but Descolada is the expert here not me.
Code: Select all
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen
SendMode Input
#SingleInstance, Force
SetTitleMatchMode 2
SetTitleMatchMode, Fast
SetControlDelay -1
SetWinDelay -1
SetKeyDelay -1
SetMouseDelay 1
SetBatchLines -1
ListLines, Off
#Persistent
#include <UIA_Interface>
GetDavinciElement() ; this runs just once as soon script is loaded
if !(dvEl := GetDavinciElement()) ; if Davinci not exist, do nothing
return
d::
;~ UIA := UIA_Interface() ; I don't think we need this
dvEl.FindFirstByName("Media Pool").Click()
return
b::
Inspector := dvEl.FindFirstByName("Inspector")
; not everything lets you click, so this is how you MOUSEclick on something with UIA
Coords := Inspector.CurrentBoundingRectangle
MouseClick, Left, (Coords.l+((Coords.r-Coords.l)/ 2)) , (Coords.t + ((Coords.b-Coords.t)/2)), 1, 9
return
~Esc::ExitApp
;;======================= FUNCTION ===============================
GetDavinciElement() {
static davinciId, davinciElement
if (!(dvId := WinExist("ahk_exe Resolve.exe")))
return
if ((davinciId == dvId) && davinciElement)
return davinciElement
else {
davinciElement := "", davinciId := dvId
while (!davinciElement && WinExist("ahk_exe Resolve.exe")) {
try davinciElement := UIA_Interface().ElementFromHandle(dvId)
}
return davinciElement
}
}
Code: Select all
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen
SendMode Input
#SingleInstance, Force
SetTitleMatchMode 2
SetTitleMatchMode, Fast
SetControlDelay -1
SetWinDelay -1
SetKeyDelay -1
SetMouseDelay 1
SetBatchLines -1
ListLines, Off
#Persistent
#include <UIA_Interface>
d::
if !(dvEl := GetDavinciElement()) ; if Davinci not exist, do nothing
return
dvEl.FindFirstByName("Media Pool").Click()
dvEl.FindFirstByName("Inspector").Click("left")
; not everything lets you click, so this is how you MOUSEclick on something with UIA
return
~Esc::ExitApp
;;======================= FUNCTION ===============================
GetDavinciElement() {
static davinciId, davinciElement
if (!(dvId := WinExist("ahk_exe Resolve.exe")))
return
if ((davinciId == dvId) && davinciElement)
return davinciElement
else {
davinciElement := "", davinciId := dvId
while (!davinciElement && WinExist("ahk_exe Resolve.exe")) {
try davinciElement := UIA_Interface().ElementFromHandle(dvId)
}
return davinciElement
}
Code: Select all
MediaTab := UIA_Interface().ElementFromHandle(WinExist("ahk_exe Resolve.exe"))
Metadata := MediaTab.FindFirstByNameAndType("Metadata", "checkbox").ToggleState
If (Matadata == True) {
MsgBox, Matadata panel is visible
}
else {
MsgBox, Matadata panel isn't visible
}
G'day....It's complex cause there are sooo many checkboxes .k0stell0 wrote:Davinci has a lot of checkboxes I need to click on,
Code: Select all
#include <UIA_Interface>
d::
UIA := UIA_Interface()
dvEl := UIA.ElementFromHandle(WinExist("DaVinci Resolve"))
;This searches the area confined to the MetadataPanel area
MetadataPanel := dvEl.FindFirstBy("AutomationId=UiMainWindow.bigBossWidget.widgetStack_Panel.WStackPage_Conform.m_pConformPanel.frameEditPageWidgetsContainer.frameEditPageMetadata")
Find1 := MetadataPanel.FindFirstByName("Good Take") ,
tw := UIA.CreateTreeWalker(UIA.CreateCondition("ControlType", "checkbox")) ; creates a treewalker
CheckBoxGoodTake := tw.GetNextSiblingElement(Find1) ; Checks next Sibling from Good Take
if CheckBoxGoodTake ; If not toggled then it will toggle checkbox on.
togglePattern := CheckBoxGoodTake.GetCurrentPatternAs("Toggle")
if !togglePattern.CurrentToggleState ; remove the "!" if you want opposite (to toggle Off) or ....remove the whole line to keep toggling on and Off without checking
togglePattern.Toggle()
return
~Esc::ExitApp
Code: Select all
#include <UIA_Interface>
d::
if !(dvEl := GetDavinciElement())
return
UIA := UIA_Interface() ; Treewalker needs this which negates the use of the GetDavinciElement()) funciton
MetadataPanel := dvEl.FindFirstBy("AutomationId=UiMainWindow.bigBossWidget.widgetStack_Panel.WStackPage_Conform.m_pConformPanel.frameEditPageWidgetsContainer.frameEditPageMetadata")
Find1 := MetadataPanel.FindFirstByName("Good Take")
tw := UIA.CreateTreeWalker(UIA.CreateCondition("ControlType", "checkbox")) I tried replacing UIA with dvEl but it didn't work
CheckBoxGoodTake := tw.GetNextSiblingElement(Find1)
if CheckBoxGoodTake
togglePattern := CheckBoxGoodTake.GetCurrentPatternAs("Toggle")
togglePattern.Toggle()
return
~Esc::ExitApp
;;======================= FUNCTION ===============================
GetDavinciElement() {
static davinciId, davinciElement
if (!(dvId := WinExist("ahk_exe Resolve.exe")))
return
if ((davinciId == dvId) && davinciElement)
return davinciElement
else {
davinciElement := "", davinciId := dvId
while (!davinciElement && WinExist("ahk_exe Resolve.exe")) {
try davinciElement := UIA_Interface().ElementFromHandle(dvId)
}
return davinciElement
}
}
Code: Select all
Find1 := MetadataPanel.FindFirstByName("Good Take")
CheckBoxGoodTake := Find1.FindByPath("+1", "Type=CheckBox")
Code: Select all
CheckBoxGoodTake := tw.GetNextSiblingElement(Find1)
if CheckBoxGoodTake
CheckBoxGoodTake.TogglePattern.ToggleState := 1 ; 1 is checked, 0 is unchecked
Code: Select all
Metadata := MediaTab.FindFirstByNameAndType("Metadata", "checkbox").ToggleState
If (Metadata == True) { ; or try "if Metadata {" instead
Sorry for any confusion, YES my code works perfectly.
Code: Select all
if (!Find1) {
; The first element wasn't found, so you can't proceed with the TreeWalker
; Switch tabs and try again?
return
}
CheckBoxGoodTake := tw.GetNextSiblingElement(Find1)
Code: Select all
try {
Find1 := MetadataPanel.FindFirstByName("Good Take")
CheckBoxGoodTake := tw.GetNextSiblingElement(Find1)
} catch {
; Something went wrong
}
When using FindByPath, that error won't be thrown but you won't know where the search was unsuccessful.
[code]CheckBoxGoodTake := MetadataPanel.FindFirstByName("Good Take").FindByPath("+1", "Type=CheckBox") ; Was MetadataPanel not found? Or "Good Take"? Or a checkbox wasn't found? Hard to tell here
Users browsing this forum: Bing [Bot], Google [Bot], Rxbie and 241 guests