Imagemarks Topic is solved

A forum dedicated to George scripting questions
Post Reply
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Imagemarks

Post by schwarzgrau »

I'm fiddling around with George, for the first time, so maybe there are some things I misunderstood: I try to write a script which analyses the previous and the next image mark and then sets the current image to an image mark, depending on the other two image marks.

I've already got a script which tells me what the previous and next image marks are

Code: Select all

mark[0] = "EMPTY"
mark[1] = "BLUE"
mark[2] = "GREEN"
mark[3] = "ORANGE"
mark[4] = "RED"
mark[5] = "PINK"
mark[6] = "GREY"

tv_exposurenext
Nimage = result
tv_LayerMarkGet 0 Nimage
NimageM = result

tv_exposureprev
tv_exposureprev
Pimage = result
tv_LayerMarkGet 0 Pimage
PimageM = result

tv_exposurenext
PRINT "previousmark: " mark[PimageM] "+" "nextmark: " mark[NimageM]
Unfortunately it only works if the next/previous image mark is on a keyframe and if there is no keyframe inbetween the current frame and the image mark.
Is there some command I could use to get the info about the next/previous image mark even if there are not on the next keyframe ? And is it correct, that you need to go to a frame to get some info about it ?
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Imagemarks

Post by NathanOtano »

You have to use some loops like WHILE or DO...UNTIL to check all the next frames until you meet an image mark :) something like this prints next image mark color and position :
//Gets current image

tv_LayerGetImage
ImMarkPos = Result

//Tests each next frame until it founds an image mark

DO
ImMarkPos = ImMarkPos +1
tv_LayerMarkGet 0 ImMarkPos
ImMarkColor = result
UNTIL (ImMarkColor != 0)

//Prints Image Mark Color Number + It's Frame Position

Print ImMarkColor" "ImMarkPos
You don't have to go to the frame, you just check it's positions's image mark with the tv_layermarkget second variable
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Imagemarks

Post by schwarzgrau »

Ah of course a loop! Thank you so much Nathan, I guess this gives me a great starting point for george scripting in general. I'll post my code here if I've done the rest.

EDIT: oh by the way do you know how to add something like a breakout? Something like pressing escape to cancel the script ? I tried to remove all marks and run the script, what causes TVPaint to crash.
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Imagemarks

Post by schwarzgrau »

I guess this script is too custom built to be useful for anyone other than me, but I thought I could share it anyway, at least here in the george sectiobn.

Code: Select all

//Set order of colors
mark[0] = 0
mark[4] = 1
mark[2] = 2
mark[3] = 3
mark[5] = 4
mark[1] = 5
mark[6] = 6

color[0] = 0
color[1] = 4
color[2] = 2
color[3] = 3
color[4] = 5
color[5] = 1
color[6] = 6


//Get current image

tv_LayerGetImage
CPos = Result 
NextMarkPos = Cpos
PrevMarkPos = CPos


//Get last image

tv_LastImage
Lpos = Result


//Tests each next frame until it founds an image mark

DO
NextMarkPos = NextMarkPos +1
tv_LayerMarkGet 0 NextMarkPos
NextMarkColor = result
UNTIL (NextMarkColor != 0 || NextMarkPos == Lpos) 


//Tests each previous frame until it founds an image mark

DO
PrevMarkPos = PrevMarkPos -1
tv_LayerMarkGet 0 PrevMarkPos
PrevMarkColor = result
UNTIL (PrevMarkColor != 0 || PrevMarkPos == 0)


//Which color number is smaller?

NMC = mark[NextMarkColor]
PMC = mark[PrevMarkColor]

IF (NMC == 0 || PMC == 0 )
	wert = 1
ELSE
	IF (NMC < PMC)
		wert = PMC +1
	ELSE
		wert = NMC +1
	END
END


//Set color

Ccol = color[wert]
tv_LayerMarkSet 0 Cpos Ccol
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Imagemarks

Post by NathanOtano »

schwarzgrau wrote: oh by the way do you know how to add something like a breakout? Something like pressing escape to cancel the script ? I tried to remove all marks and run the script, what causes TVPaint to crash.
When a script is looping or taking to long, you can press escape to exit the script. If TVP crashes It's a bug... :D

To avoid problems with your script you have to treat several use cases like "If outside layer at the beginning, exit script (or loop the the other end)" for exemple, or in your loop you can add a "test if i'm at the end/beginning of the layer, if so print "No image mark" and exit the script" to avoid infinite loop :)
But I see you already found workarounds in your script :mrgreen:

If I remember well, unfortunately you can't really use the "break" function to escape loops like in other languages : http://forum.tvpaint.com/viewtopic.php? ... eak#p90242" onclick="window.open(this.href);return false;

Don't hesitate to share your script and describe it :) it's always usefull to be able to use code lines of others even it the script himself doesn't fit our workflow
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Imagemarks

Post by schwarzgrau »

NathanOtano wrote:When a script is looping or taking to long, you can press escape to exit the script. If TVP crashes It's a bug... :D
Really? Cause if I removed all image marks and run the script my cursor instantly became the spinning wheel and I had to force quit TVPaint. Escape didn't stop it.

NathanOtano wrote: To avoid problems with your script you have to treat several use cases like "If outside layer at the beginning, exit script (or loop the the other end)" for exemple, or in your loop you can add a "test if i'm at the end/beginning of the layer, if so print "No image mark" and exit the script" to avoid infinite loop :)
But I see you already found workarounds in your script :mrgreen:
Hehe yea, It was really annoying to restart TVPaint every time I did a mistake
NathanOtano wrote: If I remember well, unfortunately you can't really use the "break" function to escape loops like in other languages : http://forum.tvpaint.com/viewtopic.php? ... eak#p90242" onclick="window.open(this.href);return false;
Ah at least good to know

NathanOtano wrote: Don't hesitate to share your script and describe it :) it's always usefull to be able to use code lines of others even it the script himself doesn't fit our workflow
I can't imagine someone on this forum can use some of my script, but maybe some future scripts could be partly helpful for others, if George and I will be friends.

Again: Thank you a lot for helping me understand the way george scripting works in TVPaint
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Imagemarks

Post by Svengali »

NathanOtano wrote:If I remember well, unfortunately you can't really use the "break" function to escape loops like in other languages : http://forum.tvpaint.com/viewtopic.php? ... eak#p90242" onclick="window.open(this.href);return false;
There is a simple workaround for the problematic "BREAK" command...

Sven
TVP Pro 11.0.10-64bit Win10 - 64GB ram -2TB HHD - 256GB SSD - Wacom Cintiq 16, driver 6.3.41-1
Android Tablet: rel. 11, Samsung Galaxy Note10.1 - 32GB with microSD 32GB
Android Tablet: rel. 11.5, Samsung Galaxy Tab S7plus - 128GB with microSD 64GB
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Imagemarks

Post by NathanOtano »

Thanks Sven! You mean that if I create a function of my loop and put an EXIT in it it acts like a BREAK? It does'nt work when it's not a function right? Nice I have to test that
Really? Cause if I removed all image marks and run the script my cursor instantly became the spinning wheel and I had to force quit TVPaint. Escape didn't stop it.
I have to check that. I know that I can espace scripts sometimes, but maybe not when looping?
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Imagemarks

Post by Svengali »

double post, sorry
Last edited by Svengali on 20 May 2016, 13:31, edited 1 time in total.
TVP Pro 11.0.10-64bit Win10 - 64GB ram -2TB HHD - 256GB SSD - Wacom Cintiq 16, driver 6.3.41-1
Android Tablet: rel. 11, Samsung Galaxy Note10.1 - 32GB with microSD 32GB
Android Tablet: rel. 11.5, Samsung Galaxy Tab S7plus - 128GB with microSD 64GB
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Imagemarks

Post by Svengali »

Sorry, I forgot that post referred to exiting out of a Function and out of a script.

trapping for infinite loops:

alternative to BREAK in a For/Next loop - example:

Code: Select all

FOR i = 1 to 20
  tv_warn "i = " i
  IF i == 5  // whenever your test becomes true, set the loop counter beyond the scope of the loop
    i = 1000
  END
END
tv_warn "exited loop iteration 5"
Also, trap for infinite DO loops by adding an incrementing counter inside the loop, then test it each iteration, so you can EXIT after some maximum iteration.

Sven
TVP Pro 11.0.10-64bit Win10 - 64GB ram -2TB HHD - 256GB SSD - Wacom Cintiq 16, driver 6.3.41-1
Android Tablet: rel. 11, Samsung Galaxy Note10.1 - 32GB with microSD 32GB
Android Tablet: rel. 11.5, Samsung Galaxy Tab S7plus - 128GB with microSD 64GB
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Imagemarks

Post by NathanOtano »

Ok, I do this kind of things too :) thanks!
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Imagemarks

Post by schwarzgrau »

Very helpful, thank you Sven
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Imagemarks

Post by schwarzgrau »

I noticed a bug in my script. If you try to use it on the first or last frame of a layer it will crash TVPaint. This is the fixed version.

Code: Select all

mark[0] = 0
mark[4] = 1
mark[2] = 2
mark[3] = 3
mark[5] = 4
mark[1] = 5
mark[6] = 6
mark[12] = 7

color[0] = 0
color[1] = 4
color[2] = 2
color[3] = 3
color[4] = 5
color[5] = 1
color[6] = 6
color[7] = 12

//Gets current image

tv_LayerGetImage
CPos = Result 

tv_LastImage
Lpos = Result

NextMarkPos = Cpos
PrevMarkPos = CPos

//Tests each next frame until it founds an image mark

IF (Cpos != Lpos) 
	DO
		NextMarkPos = NextMarkPos +1
		tv_LayerMarkGet 0 NextMarkPos
		NextMarkColor = result
	UNTIL (NextMarkColor != 0 || NextMarkPos == Lpos) 
ELSE 
	NextMarkColor = 0
END

//Tests each previous frame until it founds an image mark

IF (Cpos != 0) 
	DO
		PrevMarkPos = PrevMarkPos -1
		tv_LayerMarkGet 0 PrevMarkPos
		PrevMarkColor = result
	UNTIL (PrevMarkColor != 0 || PrevMarkPos == 0)
ELSE 
	PrevMarkColor = 0
END

//Which color number is smaller?

NMC = mark[NextMarkColor]
PMC = mark[PrevMarkColor]

IF (NMC == 0 || PMC == 0 )
	wert = 1
ELSE
	IF (NMC < PMC)
		wert = PMC +1
	ELSE
		wert = NMC +1
	END
END

//Set color

Ccol = color[wert]
tv_LayerMarkSet 0 Cpos Ccol
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
Post Reply