IF/ELSE + Tv_ functions

A forum dedicated to George scripting questions
Post Reply
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

IF/ELSE + Tv_ functions

Post by NathanOtano »

Hey!

I'm beginning in George Scripts and i'm trying to insert a TV_ function in a IF/ELSE process with variables (like == or !=). I've read that in the wiki :
Do not confuse lines to be used by George (which start with the # character) and TVPaint command lines (which all start with tv_). Lines to be used by George from program structure (loops, tests, calculations, ...), whereas lines that contain TVPaint commands affect TVPaint panels and screens.
Do i have to put a prefix or something before the function, or any other way, to make it work?

EDIT : Ok i'm beginning to understand how all works... Is there a way to return the number of exposure of the current instance? To go to the head/tail of an instance? To go to the prev/next instance (like tv_exposureprev/next)?

Nathan
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
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: IF/ELSE + Tv_ functions

Post by Mads Juul »

NathanOtano wrote: Is there a way to return the number of exposure of the current instance? To go to the head/tail of and instance? To go to the prev/next instance?
There is no direct George command
If you would like one You can +1 my feature request here
http://forum.tvpaint.com/viewtopic.php? ... 924#p18924

But you can get it in several other ways with GEORGE. you can for instance use tv_exposureinfo with some WHILE loops

Code: Select all

PARAM none

num = instance_exposures()
tv_warn num


FUNCTION instance_exposures()
	LOCAL IID firsttype trash i run type startIID endIID delta
	tv_LayerGetImage
	IID = result
	tv_exposureinfo IID
	PARSE result firsttype trash
	delta=0
	IF CMP(firsttype,"head")==1
		i=IID
		startIID = IID
		run=1
		WHILE run
			i=i+1
			tv_exposureinfo i
			PARSE result type trash
			IF CMP(type,"exposure")==0
				run=0
				endIID=i
			END
			
		END
		delta = endIID-startIID
	END
	IF CMP(firsttype,"exposure")==1
		i=IID
		run=1
		WHILE run
			i=i-1
			tv_exposureinfo i
			PARSE result type trash
			IF CMP(type,"exposure")==0
				run=0
				startIID=i
			END
		END
		
		i=IID
		run=1
		WHILE run
			tv_exposureinfo i
			PARSE result type trash
			IF CMP(type,"exposure")==0
				run=0
				endIID=i
			END
			i=i+1
		END
	
		delta = endIID-startIID
	END
	result = delta
	RETURN result
END

You could also use tv_exposureInfo combined with tv_exposureNext and tv_exposurePrev

Code: Select all

PARAM none

num = instance_exposures()
tv_warn num

FUNCTION instance_exposures()
	LOCAL IID type trash startIID endIID delta
	tv_LayerGetImage
	IID = result
	tv_exposureinfo IID
	PARSE result type trash
	delta=0
	IF CMP(type,"head")==1
		startIID = IID
		tv_exposureNext
		endIID = result
		delta = endIID-startIID
	END
	IF CMP(type,"exposure")==1
		tv_exposurePrev
		tv_exposureNext
		startIID = result
		tv_exposureNext
		endIID = result
		delta = endIID-startIID
	END
	tv_LayerImage IID
	result = delta
	RETURN result
END

hope it helps.
Maybe others have better solutions?

-Mads
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: IF/ELSE + Tv_ functions

Post by NathanOtano »

Those are too complicated for me haha, i'll study this :) thank you, i'll try it soon.

And for executing a tv function if something is true?
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
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: IF/ELSE + Tv_ functions

Post by Mads Juul »

NathanOtano wrote:Those are too complicated for me haha, i'll study this :) thank you, i'll try it soon.

And for executing a tv function if something is true?
There is 2 main ways to run a script in Tvpaint
1) with an embeded script in an action in custom panel
2) saved as a text file with the ending .grg and run with an action in a custom panel

Do you understand this?


So you can either use this code in a text file(.grg) or embedded(this is probably the easiest for you)

HEre I test if Im on frame 2

Code: Select all

// get current frame
tv_layerimage
curFrame = result
// the tvpaint function return a variable called "result" i assign this result to another variable called "curFrame"
// now I test if the current frame is equal to 2
IF CMP(curFrame,"2")==1
tv_warn "You are on frame 2"
ELSE
tv_warn "You are not on frame 2"
END
I use CMP(curFrame,"2") instead of IF curFrame==2
because I also can compare strings with CMP
For instance

Code: Select all

myanimal="cat"

IF CMP(myanimal,"cat")==1
tv_warn "mouse"
ELSE
tv_warn "dog"
END


Does it make any sense?
-Mads
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: IF/ELSE + Tv_ functions

Post by NathanOtano »

Yes i understand the ways to run the scripts, that part was ok.
for your first script on your last post, i think you wanted to use tv_layergetimage and not tv_layerimage, no?

I tried it, so actually you just CAN use a tv function on a if/else process? For my case i figured out where was the problem, thank you for you help.

My problem was that i'm trying to adapt a script by svengali (to loop frame moves) but for instances (already adapted the last part) :

Code: Select all

//  PreviousFrame.grg
//  By Svengali
//	Move to previous frame and if first, loops to last
// 	version 0.0

Param none
ScriptName = 'PreviousFrame'

//tv_LockDisplay

//tv_LayerID
tv_LayerCurrentID
parse result LayerNumber

tv_LayerInfo LayerNumber
	parse result d d d d LayerType LayerStart LayerEnd d d d

StrTest = CMP (LayerType,"Sequence")

IF (StrTest = 0)
	Exit
END

tv_
tv_LayerGetImage
parse result ThisFrame

IF (ThisFrame == LayerStart)
	ThisFrame = LayerEnd
ELSE
ThisFrame = ThisFrame-1
END

IF (ThisFrame > LayerEnd)
	ThisFrame = LayerEnd
END
IF (ThisFrame < LayerStart)
	ThisFrame = LayerEnd
END

tv_LayerImage ThisFrame

//tv_UnLockDisplay
And i wanted to adapt this part :

Code: Select all

IF (ThisFrame == LayerStart)
	ThisFrame = LayerEnd
ELSE
ThisFrame = ThisFrame+1
END
I tried, after the ELSE, to put "tv_ExposureNext" (but now i know that i doesn't go to next instance but just next frame) and it doesn't go to the next exposure, it does nothing because of the "tv_LayerImage ThisFrame" at the end of the script, and that's very logical because now i understand how it works...

But i'm still trying to find a solution to loop instances navigation :) if somebody have an idea. That's why i'm searching functions to go to the head/tail of an instance.
Last edited by NathanOtano on 07 May 2014, 16:49, edited 1 time in total.
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
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: IF/ELSE + Tv_ functions

Post by NathanOtano »

Ok Done :3

Code: Select all

tv_LayerCurrentID
parse result LayerNumber

tv_LayerInfo LayerNumber
	parse result d d d d LayerType LayerStart LayerEnd d d d

tv_LayerGetImage
parse result ThisFrame

IF (ThisFrame == LayerStart)
	ThisFrame = LayerEnd
ThisFrame = ThisFrame+1
ELSE
ThisFrame = ThisFrame-1
END

IF (ThisFrame > LayerEnd)
	ThisFrame = LayerEnd
END
IF (ThisFrame < LayerStart)
	ThisFrame = LayerEnd
END

tv_LayerImage ThisFrame
With go to head before and after the script on my panel button.
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.
Post Reply