[SOLVED] Move to Duplicate Clip

A forum dedicated to George scripting questions
Post Reply
cursived
Posts: 4
Joined: 25 Jul 2016, 23:51
Contact:

[SOLVED] Move to Duplicate Clip

Post by cursived »

Hi TVPaint Community,
I am working on a george script that duplicates the current clip then moves to the new clip. I though it would be something like;

Code: Select all

tv_clipselect tv_clipcurrentid+1
But it just gives me an execution error.

Any help would be greatly appreciated
Last edited by cursived on 03 Nov 2016, 16:43, edited 1 time in total.
Darren M. OConnell
CursiveD.com
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Move to Duplicate Clip

Post by schwarzgrau »

I guess you have a wrong idea of how george scripts work, which seems to be normal, since the beginning isn't that well documented It seems.
However, you need to use the functions one by one (in your example you use two in one line)

To get the ID of the current clip you need to write

Code: Select all

tv_clipcurrent //this is a function which gives you the ID of the current clip
curClipID = Result // then you need to feed the result in a variable. I called it "curClipID", but you could name it "sausage" too
PRINT "CurrentClipID = "curClipID //This line will generate a pop-up-window which show the ID. It's not necessary but always good to see you really definied your variable while working on a script
I hope this helps a bit in understanding the basics.
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
cursived
Posts: 4
Joined: 25 Jul 2016, 23:51
Contact:

Re: Move to Duplicate Clip

Post by cursived »

Thank you for the quick reply. So would the next line be:

Code: Select all

tv_clipselect curClipID+1
Thanks
Darren
Darren M. OConnell
CursiveD.com
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Move to Duplicate Clip

Post by schwarzgrau »

It seems right, but unfortunately it isn't since the IDs are not numbered in an incremental way (not like 1,2,3....) more like 445, 23, ,759 etc.
Unfortunately I'm pretty new to George-scripting too and have no idea which command you would need. Layers all have an ID (random numbers) and a Position (an incremental number like 1,2,3) maybe it's the same with clips.
This function could maybe be interesting, but to be honest I don't exactly understood what it's really good for
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: Move to Duplicate Clip

Post by NathanOtano »

It was very hard to "go to the next clip with george", if you don't really need it withing your script I would advise you tu use a shortcut in your custom button instead.
For your need I think something like this is working (I havn't tested it yet, I havn't tvpaint with me):

Code: Select all

tv_clipcurrentid  //finds current clip's ID
ClipID = result // stores it in the variable ClipID

//Starting a loop to find current clip position
	ClipPos = 0 //start the loop with clip at position 0
	tv_ClipEnumID -1 ClipPos
	PosID = result  //gets clip's ID of the first clip

	While (CMP(PosID, ClipID)==0)  //I just add 1 to the clip position until the current clip ID matches the ID of the position
		ClipPos = ClipPos+1
		tv_ClipEnumID -1 ClipPos
		PosID = result
	END
//Last ClipPos variable is now current clip position

tv_clipduplicate ClipID //duplicates current clip

NextClipPos = ClipPos + 1 //you choose the position you want to go to, here 1 position forward
tv_ClipEnumID -1 NextClipPos //gets the ID of the clip at the position you want to go to
tv_ClipSelect result //goes 1 clip forward 
Here is some functions i made, maybe it could help people working with clips? I use them in my scripts related to storyboard, especially this one : http://forum.tvpaint.com/viewtopic.php?f=11&t=9724" onclick="window.open(this.href);return false;

You can use the Otano_Nextclip() and Otano_PrevClip() to go to the next/previous clip, it loops to the first/last clip so it's nice.
The Otano_EditingInfo() gives you all the variables you'd need to work with clips in george.
The Otano_ClipPos(ClipID) can give you the position of your clip regarding all your clips, if you put the ID of the clip in brackets. For the current clip, simply use Otano_ClipCurrentPos(). That way you can "go to the next/previous" clip using the position of your clip in your script to find the right IDs to go to.

Code: Select all

#Function Otano_ClipCurrentPos()
		LOCAL ClipID ClipPos PosID

		tv_clipcurrentid
		ClipID = result
		
		ClipPos = 0
		tv_ClipEnumID -1 ClipPos
		PosID = result
		
		While (CMP(PosID, ClipID)==0)
			ClipPos = ClipPos+1
			tv_ClipEnumID -1 ClipPos
			PosID = result
		END

			result = ClipPos
	#End
	
#Function Otano_ClipPos(ClipID)
		LOCAL ClipPos PosID
		
		ClipPos = 0
		tv_ClipEnumID -1 ClipPos
		PosID = result
		
		While (CMP(PosID, ClipID)==0)
			ClipPos = ClipPos+1
			tv_ClipEnumID -1 ClipPos
			PosID = result
		END

			result = ClipPos
	#End

#Function Otano_ClipCount()
		LOCAL ClipPos PosID
		
		ClipPos = -1
		
		DO
			ClipPos = ClipPos+1
			tv_ClipEnumID -1 ClipPos
			PosID = result
		Until CMP(PosID,"none") == 1
		
		result = ClipPos
		
	#End
	
#Function Otano_ClipIsExtreme(ClipID)
		LOCAL clipPos clipCount clipState
		
		Otano_ClipPos(ClipID)
		clipPos=result
		
		IF ClipPos == 0
			clipState = Start
		Else
			Otano_ClipCount()
			clipCount = result
			
			IF clipCount-1 == clipPos
				clipState = End
			Else
				clipState = none
			End
		End
		
		result=clipState
		
	#End
	
#Function Otano_EditingInfo()
		LOCAL a FirstFrame LastFrame TotalLength EditStart EditEnd EditLength ClipID ClipPos MarkInFrame MarkInState MarkOutFrame MarkOutState 
		
				//Collecting Clip Infos
		tv_clipinfo
		PARSE result a a a a a a a a a a a FirstFrame a LastFrame a TotalLength a EditStart a EditEnd a
		
		EditLength = EditEnd - EditStart +1
		
		tv_clipcurrentid
		ClipID = result
		
				//Findind Clip Posistion
		Otano_ClipCurrentPos()
		ClipPos = Result
		
				//Findind and Setting Mark In/Out Infos
		tv_MarkIn clip
		parse result MarkInFrame MarkInState
		tv_MarkOut clip
		parse result MarkOutFrame MarkOutState
		
		IF (CMP(MarkInState, "set ")==1)
			MarkInState = 1
		ELSE
			MarkInState = 0
		End
		
		IF (CMP(MarkOutState, "set ")==1)
			MarkOutState = 1
		ELSE
			MarkOutState = 0
		End
		
				//result
		result =  ClipPos" "ClipID" "FirstFrame" "Lastframe" "MarkInState" "MarkOutState" "MarkInFrame" "MarkOutFrame" "TotalLength" "EditLength
		
	#End
	
#Function Otano_NextClip()
		LOCAL OriginalClipPos OriginalClipID a NextClipPos NextClipID ClipExtremeState
		
		Otano_EditingInfo()
		PARSE result OriginalClipPos OriginalClipID a
		
		Otano_ClipIsExtreme(OriginalClipID)
		Parse result ClipExtremeState
		
		IF CMP(ClipExtremeState,"End")==1
			NextClipPos = 0
			tv_ClipEnumID -1 NextClipPos
			NextClipID = result
		ELSE
			NextClipPos = OriginalClipPos + 1
			tv_ClipEnumID -1 NextClipPos
			NextClipID = result
		END
		
		tv_ClipSelect NextClipID
		
		result = OriginalClipPos" "OriginalClipID" "NextClipPos" "NextClipID
	#End
	
#Function Otano_PreviousClip()
		LOCAL OriginalClipPos OriginalClipID a PreviousClipPos PreviousClipID ClipExtremeState
		
		Otano_EditingInfo()
		PARSE result OriginalClipPos OriginalClipID a

		Otano_ClipIsExtreme(OriginalClipID)
		Parse result ClipExtremeState
		
		IF CMP(ClipExtremeState,"Start")==1
			Otano_ClipCount()
			PreviousClipPos = result - 1
			tv_ClipEnumID -1 PreviousClipPos
			PreviousClipID = result
		ELSE
			PreviousClipPos = OriginalClipPos - 1
			tv_ClipEnumID -1 PreviousClipPos
			PreviousClipID = result
		END
		
		tv_ClipSelect PreviousClipID
		
		result = OriginalClipPos" "OriginalClipID" "PreviousClipPos" "PreviousClipID
	#End
	
#Function Otano_NextClipSkipHidden()
		LOCAL OriginalClipPos OriginalClipID a NextClipPos NextClipID ClipExtremeState
		
		Otano_EditingInfo()
		PARSE result OriginalClipPos OriginalClipID a
		
		NextClipPos = OriginalClipPos
		
		tv_ClipEnumID -1 NextClipPos
		NextClipID = Result
		
		DO 
			Otano_ClipIsExtreme(NextClipID)
			Parse result ClipExtremeState
		
			IF CMP(ClipExtremeState,"End")==1
				NextClipPos = 0
				tv_ClipEnumID -1 NextClipPos
				NextClipID = result
			ELSE
				NextClipPos = NextClipPos + 1
				tv_ClipEnumID -1 NextClipPos
				NextClipID = result
			END
			
			tv_clipHidden NextClipID
			Hidden = result
		Until Hidden == 0
		
		tv_ClipSelect NextClipID
		
		result = OriginalClipPos" "OriginalClipID" "NextClipPos" "NextClipID
	#End
	
#Function Otano_PreviousClipSkipHidden()
		LOCAL OriginalClipPos OriginalClipID a PrevClipPos PrevClipID ClipExtremeState
		
		Otano_EditingInfo()
		PARSE result OriginalClipPos OriginalClipID a
		
		PrevClipPos = OriginalClipPos
		
		tv_ClipEnumID -1 PrevClipPos
		PrevClipID = Result
		
		DO 
			Otano_ClipIsExtreme(PrevClipID)
			Parse result ClipExtremeState
		
			IF CMP(ClipExtremeState,"Start")==1
				Otano_ClipCount()
				PrevClipPos = result - 1
				tv_ClipEnumID -1 PrevClipPos
				PrevClipID = result
			ELSE
				PrevClipPos = PrevClipPos - 1
				tv_ClipEnumID -1 PrevClipPos
				PrevClipID = result
			END
			
			tv_clipHidden PrevClipID
			Hidden = result
		Until Hidden == 0
		
		tv_ClipSelect PrevClipID
		
		result = OriginalClipPos" "OriginalClipID" "PrevClipPos" "PrevClipID
	#End
Last edited by NathanOtano on 30 Oct 2016, 15:26, edited 2 times 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
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Move to Duplicate Clip

Post by schwarzgrau »

Pretty useful! You should add them to User Made Procedures in the Wiki
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: Move to Duplicate Clip

Post by NathanOtano »

Yeah that's something I have to do "someday" haha, I've so much things to do. But I can share my library anytime if somebody wants to help me put it in the wiki :)
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: Move to Duplicate Clip

Post by schwarzgrau »

Hehe someday I will help you with 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
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Move to Duplicate Clip

Post by Svengali »

Its a little goofy, but I think this will do what you want. It builds on the Wiki example in the clips section.

The most difficult thing was how to finish with the duplicate selected... it would really help if the tv_ClipDuplicate command returned the new ClipID for the duplicated clip.

Instead I had to loop with a counter to find the original and duplicate clips. :?

Code: Select all

// ClipDup.grg
// Svengali © 2016
// duplicates currentclip and selects the new duplicate
// (Oct) 2016 - ver .0

Param none
ScriptName = "ClipDup"

tv_LockDisplay quiet
tv_ClipCurrentID
OrigID = result							// get the original clip ID
tv_ClipDuplicate						// duplicate the original clip

ClipFlag = 1							// set flag true
ClipCounter = 0							// init counter
While ClipFlag							// loop while flag is true
	tv_ClipEnumID -1 ClipCounter		// get ID for each clip
	ClipID = result						// store ID for current clip
	ClipCounter = ClipCounter + 1		// increment counter
	IF CMP(ClipID,OrigID)				// is this the original clip?
		tv_ClipEnumID -1 ClipCounter	// get ID for duplicate clip
		DupID = result					// store ID for duplicate clip
		tv_ClipSelect DupID				// select duplicate clip
		ClipFlag = 0					// set flag to false		
	END
END
tv_UnLockDisplay
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
cursived
Posts: 4
Joined: 25 Jul 2016, 23:51
Contact:

Re: Move to Duplicate Clip

Post by cursived »

Thanks everyone for the help. I agree with Svengali that tv_ClipDuplicate should return the new clip id, or if they had a build in function to access the next clip (tv_ClipNext maybe?) or at least make them logical (ie if the current is 789 then the next should be 790)

I just integrated Svengali's code with the rest of my script.
For those that are interested here is my full project

Code: Select all

//LDS George Script
//By Darren M. OConnell
//Code Contributed by Svengali
//This script locks all layers, duplicates the current clip, and then saves the project

//The askSave() will prompt the user for location each time it runs
FUNCTION clipSelect()
	tv_clipcurrentid  //finds current clip's ID
	ClipID = result // stores it in the variable ClipID

	//Starting a loop to find current clip position
	   ClipPos = 0 //start the loop with clip at position 0
	   tv_ClipEnumID -1 ClipPos
	   PosID = result  //gets clip's ID of the first clip

	   While (CMP(PosID, ClipID)==0)  //I just add 1 to the clip position until the current clip ID matches the ID of the position
	      ClipPos = ClipPos+1
	      tv_ClipEnumID -1 ClipPos
	      PosID = result
	   END
	//Last ClipPos variable is now current clip position

	NextClipPos = ClipPos + 1 //you choose the position you want to go to, here 1 position forward
	tv_ClipEnumID -1 NextClipPos //gets the ID of the clip at the position you want to go to
	tv_ClipSelect result //goes 1 clip forward
END

//Locks all Layers, Duplicates current clip, then changes to new clip
FUNCTION lockDup()
	ExitFlag = 0
	Counter = 0

	While ExitFlag == 0
	   tv_LayerGetID Counter
	   LayerID = result
	   IF CMP(LayerID, "none")
	      Total = Counter - 1
	      ExitFlag = 1
	   ELSE
	      //tv_LayerInfo LayerID
				tv_layerlock LayerID on
	   END
	   Counter = Counter + 1
	END
	tv_clipduplicate tv_clipcurrentid
	clipSelect()


END


//Turn of Layer Locks Off On Current Clip
FUNCTION lockOff()
	ExitFlag = 0
	Counter = 0

	While ExitFlag == 0
	   tv_LayerGetID Counter
	   LayerID = result
	   IF CMP(LayerID, "none")
	      Total = Counter - 1
	      ExitFlag = 1
	   ELSE
	      tv_layerlock LayerID off
	   END
	   Counter = Counter + 1
	END


END


//Script Main
lockDup()
lockOff()
Darren M. OConnell
CursiveD.com
Post Reply