Please help me fix this loop

Get help with using AutoHotkey and its commands and hotkeys
Grayline
Posts: 1
Joined: 02 Aug 2018, 01:46

Please help me fix this loop

02 Aug 2018, 02:41

Hi guys,

Firstly, thank you for taking the time to see if you can help me. I just want to mention that I am in no way a programmer. Everything I've coded to this point was through research on this amazing forum. I am a full time video editor looking to streamline my workflow.

Right now, the code below does the following:
  • 1. User presses CTRL 1
    2. AutoHotKey starts the 'addWarpStabilizer' function
    3. It does several checks namely:
    • a. It checks if the last clip on the timeline already has a white matte layer. If yes, it exists the function. If no, it goes back to the beginning of the timeline.
      b. It checks if the current clip has a white matte. If yes, it moves to the next clip. If no, it adds a white matte to the clip and then it moves the next clip.
    4. Now the function is complete and it stops the script.
I've managed to get it to work as described above, but I am trying to incorporate a loop between check point a and check point b. (so that check point b runs continuously through the timeline and keeps adding a white matte to each new clip.) Every method of inserting a loop has made my computer freak out completely. Ideally I'd like to build in a fail safe that if the loop is not acting as expected I can just press escape to stop it. Is the aforementioned possible?

You'll notice my latest attempt at a loop is commented out in the code below.

Code: Select all


;<<<<<<<<<<<<<<<<<<<<<<< This script allows you to apply warp stabilizer to every clip in the timeline, one at a time in consecutive order. Press Escape to stop the loop. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


^1:: addWarpStabilizer("Add Warp")

addWarpStabilizer(addWarp)
{
ifWinNotActive ahk_exe Adobe Premiere Pro.exe
	goto warpEnding 
;keyShower(addWarp, "addWarpStabilizer")
if IsFunc("Keyshower") {
	Func := Func("Keyshower")
	RetVal := Func.Call(addWarp, "addWarpStabilizer") 
}

CoordMode, mouse, Screen
CoordMode, pixel, Screen
coordmode, Caret, screen


;******** Preparing Script **********
BlockInput, mouse
blockinput, MouseMove
BlockInput, On
SetKeyDelay, 0 ;for instant writing of text
;sendinput, +!0; <<<<--- This resets the current workflow to the original state.
;sleep 200
MouseGetPos, xpos3, ypos3
;******** Script Prepared ***********


;********** Check if last clip already has white matte *************



sendinput, +1 ;<<<<--- Change to effects panel
sleep 10
sendinput, +3 ;<<<<--- Change to timeline panel
sleep 10
sendinput, v  ;<<<<--- Make sure selection tool is enabled
sleep 20
sendinput, ^+!e ;<<<<--- Go to end of sequence
sleep 1000 ;<<<<--- Increase this time on slower computers
send ^!p ;<<<<--- Go to previous edit point. (We should now be on the last edit point right before the ending)
sleep 4000
MouseMove, 2874, 504, 0 ;<<<<--- Move curser to middle of Program monitor.
sleep 10
MouseGetPos MouseX, MouseY ;<<<<--- This stores the coordinates where your mouse is at.
sleep 10
PixelGetColor, color, %MouseX%, %MouseY%, RGB ;<<<<--- This saves the color of the coordinates mentioned above.
sleep 10

if (color = 0xffffff){ ;<<<<--------- This is the color of the white matte. 	
	MouseMove, %xpos3%, %ypos3%, 0							
	goto warpEnding										
	}												
													
;********** End of Check ***********

else
	{


;************ Check if current clip already has white matte *****************

	sleep 100
	sendinput, ^+!x
	sleep 4000



;	Loop 
;
;	{
;	if {(breakLoop = 1)
;		break
;	}

	sendinput, +1 ;<<<<--- Change to effects panel
	sleep 10
	sendinput, +3 ;<<<<--- Change to timeline panel
	sleep 10
	sendinput, v  ;<<<<--- Make sure selection tool is enabled
	sleep 20
	MouseMove, 2874, 504, 0 ;<<<<--- Move curser to middle of Program monitor.
	sleep 1000
	MouseGetPos MouseX2, MouseY2 ;<<<<--- This stores the coordinates where your mouse is at.
	sleep 10
	PixelGetColor, color2, %MouseX2%, %MouseY2%, RGB ;<<<<--- This saves the color of the coordinates mentioned above.
	sleep 10

	if (color2 = 0xffffff){ ;<<<<--------- This is the color of the white matte. 	
		
		sendinput, +1 ;<<<<--- Change to effects panel
		sleep 10
		sendinput, +3 ;<<<<--- Change to timeline panel
		sleep 10
		sendinput, v  ;<<<<--- Make sure selection tool is enabled
		sleep 20
		send ^+!]
		sleep 4000
		MouseMove, 2874, 504, 0 ;<<<<--- Move curser to middle of Program monitor.
		sleep 10
		MouseGetPos MouseX3, MouseY3 ;<<<<--- This stores the coordinates where your mouse is at.
		sleep 10
		PixelGetColor, color3, %MouseX3%, %MouseY3%, RGB ;<<<<--- This saves the color of the coordinates mentioned above.
		sleep 10

		if (color3 = 0xffffff){ ;<<<<--------- This is the color of the white matte. 	
			MouseMove, %xpos3%, %ypos3%, 0
			send ^+!n
			send ^!o
			sleep 4000
		}

		else {
			MsgBox Should break here if there is white matte
;			break
			goto warpEnding
		}						
										
		}									
											
;********** End of Check ***********

	else
		{
		insertWhite("White Matte")
		sleep 100
		sendinput, ^!o
		sleep 100
		}
	}
	;}

warpEnding:
BlockInput, off
BlockInput, MouseMoveOff
return
}


Vh_
Posts: 201
Joined: 17 Mar 2017, 22:06

Re: Please help me fix this loop

02 Aug 2018, 21:32

Grayline,

I'm not sure I fully understand your code, however I get your intention I believe. You may look into the 'until' loop. I had a script where I needed a continuous loop to behave on certain conditions, and then it would bounce back and forth. You can also set vars to 1 and 0 and use multiple loops to wait until something equals true, to then go into another sub routine. I can post some real examples in the next few days.. don't have them handy right now. Hopefully I remember. :)

Anyway, here is a basic quick and dirty example of what I did, although I used very nested statements as there were a lot of conditions. I hope this helps in the mean time to get some ideas. Best of luck!

Code: Select all

^1:: addWarpStabilizer("Add Warp")
X = 0
Start:

Loop
{
something.. ;I used ControlGetText in my project, until a certain button became visible, using A as the var name in this command.
} 
Until (x = a)
GoTo, SubRoutine

SubRoutine:
Loop
{
my code
}
Until (a = x)

GoTo, Start

Return to “Ask For Help”

Who is online

Users browsing this forum: Gedzas, Google [Bot] and 35 guests