Problem where Edit controls in a program are jumping around and trying to RegExMatch the correct ones
Posted: 18 Feb 2018, 14:50
Hi guys. I have this problem in Adobe Illustrator where certain edit controls that I want the information of (like x and y coordinates, width and height parameters) will jump around depending on what tool is active or what's currently selected (if a rectangle, if text, if multiple objects, etc). So I'm trying to get a list of all controls, omit everything that isn't an Edit control, then scan through these edit controls and determine what context I'm currently in. I don't know of another way to do this and I'm brand new to RegEx so I'm not sure what I'm doing wrong. Here's part of the pattern I'm trying to capture:
And a .pdf version with easy column copying in case that helps:
My reasoning is, if I can identify something unique to each of these contexts (highlighted in gold, not finished atm because there are more of these), then I'll be able to use RegExMatch to determine which context I'm in and I can then draw the correct parameters from the correct Edit controls. I've successfully done this:
My problem is that I can only seem to get reliable results when I use only one variable and one RegExMatch. If I append another condition for another match, like to search for which edit's contents end with "Stock" or "Auto" with the same above technique, I'm getting unreliable and inaccurate results. I get correct information if I do one at a time, but not if the following:
No matter if I append it to the same loop or if I separate them as loops. The only time it works is in one of my tests:
But I can't recreate it and I don't understand why. I can copy and paste this section (and the entire hotkey) and replace the "(ock)$" with "(Auto)$" and suddenly only the first RegExMatch yields a result despite me taking a RegExMatch that I know is working (from having it isolated on a different hotkey) and pasting it here, and I don't know why. What am I doing wrong here? I realize this might be a dumb way to approach this but I don't know of a better method to determine how I know which Edit controls that my x, y, w, and h parameters will be in, Illustrator has 140+ edit controls and it wouldn't be easy to determine the x,y,w or h from contents alone (often I'll have x "0 pt" like many other boxes, or stroke width will be "20 pt" and could be mistaken for a w/h parameter, etc.)
And a .pdf version with easy column copying in case that helps:
My reasoning is, if I can identify something unique to each of these contexts (highlighted in gold, not finished atm because there are more of these), then I'll be able to use RegExMatch to determine which context I'm in and I can then draw the correct parameters from the correct Edit controls. I've successfully done this:
Code: Select all
; Find Artboard
+F24::
match := []
WinGet, ControlList, ControlList, A
Artboard := ""
vOutput := ""
p := 1, m := ""
while p := RegExMatch(ControlList, "(Edit[0-9]+)", m, p + StrLen(m)) {
match%A_Index% := m1
finalCount := A_Index
}
Loop, 40
{
CurrMatch := (A_Index + 100) ; This control is always in the 100 to 140 range
ControlGetText, conMatch, % match%CurrMatch%, ahk_class illustrator
If (RegExMatch(conMatch, "(Artboard)$") != 0)
{
Artboard := match%currMatch%
}
}
MsgBox % vOutput
Return
Code: Select all
; variables are global
ScanForEdits(){
match := []
WinGet, ControlList, ControlList, A
Artboard := ""
vOutput := ""
p := 1, m := ""
while p := RegExMatch(ControlList, "(Edit[0-9]+)", m, p + StrLen(m)) {
match%A_Index% := m1
finalCount := A_Index
}
Loop, 40
{
CurrMatch := (A_Index + 100)
ControlGetText, conMatch, % match%CurrMatch%, ahk_class illustrator
If (RegExMatch(conMatch, "(Artboard)$") != 0)
{
Artboard := match%currMatch%
}
; ; Always reports 125
; If (RegExMatch(conMatch, "(ock)$") != 0)
; {
; StockVar := match%currMatch%
; }
}
; Always reports 125
; Loop, 40
; {
; CurrMatch := (A_Index + 100)
; ControlGetText, conMatch, % match%CurrMatch%, ahk_class illustrator
; If (RegExMatch(conMatch, "(ock)$") != 0)
; {
; StockVar := match%currMatch%
; }
; }
Return
}
Code: Select all
Loop, 40
{
CurrMatch := (A_Index + 100)
ControlGetText, conMatch, % match%CurrMatch%, ahk_class illustrator
If (RegExMatch(conMatch, "(Artboard)$") != 0)
{
Artboard := match%currMatch%
}
}
Loop, % finalCount
{
CurrMatch := A_Index
ControlGetText, conMatch, % match%CurrMatch%, ahk_class illustrator
If (RegExMatch(conMatch, "(ock)$") != 0)
{
StockNum := match%currMatch%
}
}