CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around) Topic is solved

A forum dedicated to George scripting questions
Post Reply
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Svengali »

For anyone writing scripts that work with Clips (storyboarding or whatever)...

Here is a rather serious kind of "Gotcha" bug (and a work-around) that I recently ran into and had to solve.

I was writing a utility that works with CLIPS and found a "parsing problem" in the tv_ClipInfo command, ONE THAT HAPPENS IF THE CLIP NAME CONTAINS ONE OR MORE SPACES.
Spoiler : :
tv_clipinfo [iClipId]

Here is the Syntax Entry for tv_clipinfo from the GEORGE LIST OF ALL COMMANDS FROM the TVPaint Website:



Get the information of the current/given clip

[PARAMETERS]
iClipId int The clip id

[RETURN]
"Name" oId "IsCurrent" 0|1 "IsHidden" 0|1 "IsSelected" 0|1 "StoryboardStartFrame" oStoryboardStartFrame "FirstFrame" oFirstFrame "LastFrame" oLastFrame "FrameCount" oFrameCount "MarkIn" oMarkIn "MarkOut" oMarkOut "ColorIdx" oColorIdx

"Name" oId string The name
"IsCurrent" 0|1 bool The current
"IsHidden" 0|1 bool The visibility
"IsSelected" 0|1 bool The selection
"StoryboardStartFrame" oStoryboardStartFrame int The start frame of the storyboard
"FirstFrame" oFirstFrame int The first frame
"LastFrame" oLastFrame int The last frame
"FrameCount" oFrameCount int The number of frame
"MarkIn" oMarkIn int The mark in
"MarkOut" oMarkOut int The mark out
"ColorIdx" oColorIdx int The color index

[ERROR]
"" string No valid iClipId
The "tv_ClipInfo bug" happens if your CLIP NAME INCLUDES ONE OR MORE SPACES, because it throws off the parsing so the wrong parameters get placed in the wrong variables.
This probably will result in an error message for that line in the script that uses tv_ClipInfo.

My work-around works like this:
First a temporary, one-word name (temp) replaces the ORIGINAL CLIP NAME which we put into a temporary variable (whether the original clip name includes spaces or not) where it is enclosed in double quotes.

The "temp" CLIP NAME makes it safe to use the tv_ClipInfo command so the resulting values are assigned to the proper variables. Except the CLIP NAME is now temp, so you need to substitute CLIP NAME variable created as part of the tv_ClipInfo command with the ORIGINAL CLIP NAME ENCLOSED IN QUOTES. Then you should finally replace the Original Clip Name (now enclosed with double quotes) back into to the clip.

Note to TVPaint Programmers:
I really think the tv_ClipInfo command should automatically allow for Clip Names that contain spaces. The bug should be taken care of, internally, by fixing the tv_ClipInfo GEORGE command so it automatically encloses the clip title in double quotes.

Here is a script and FUNCTION that properly parses the variables, matching them to their expected values, whether the CLIP NAME contains spaces or not.

Code: Select all

// ClipInfoBugTest.grg

ClipNameBugFix()

tv_warn "CName = " CName " IsCurrent = " CCurrent " isHidden = " CHidden " IsSelected = " CSelected " StoryboardStart = " CSBStartFrame " FirstFrame = " CFirstFrame " LastFrame = " CLastframe " FrameCount = " CFrameCount " MarkIn = " CMarkIn " MarkOut = " CMarkOut " Coloridx = " CColorIdx


FUNCTION ClipNameBugFix()	// traps bug for clip names which include spaces which ruins  parsing for tv_ClipInfo command
	tv_ClipCurrentID	// get current CLIP's ID
	ClipID = result
	tv_ClipName ClipID "temp"	// rename current CLIP to one word "temp"
	OriginalClipName = result		// save original CLIP name (which might include one or more spaces)
	OriginalClipName = '"' OriginalClipName '"'		// enclose original name in double quotes
	tv_ClipInfo
	parse result Name CName  IsCurrent CCurrent IsHidden CHidden IsSelected CSelected StoryboardStartFrame CSBStartFrame  FirstFrame CFirstFrame LastFrame CLastFrame FrameCount CFrameCount MarkIn CMarkIn MarkOut CMarkOut ColorIdx CColorIdx
	CName = OriginalClipName
	tv_ClipName ClipID OriginalClipName
END
sven
Last edited by Svengali on 03 Feb 2020, 05:32, 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
User avatar
Hironori Takagi
Posts: 313
Joined: 14 May 2018, 10:15
Location: Tokyo, Japan
Contact:

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Hironori Takagi »

I think common problem on using the George command is:
Use space key, double quotation, quotation (they are separator characters),
and automatically translation of string to number (for example, input "0001" become "1").

Here is my method:
・Use tv_ClipName instead of tv_ClipInfo to get ClipName
・Use xxx = CONCAT ("_", result) - stop automatically translation
・Use name = (CUT (xxx, 2, LEN(xxx))) - when outputting

Perhaps even this is not perfect.
TVPaint 11.7.2(Nov 14 2023), Windows11 Pro, HP Spectre x360 Convertible 14-ea0xxx / TVPaint 11.7.1(Dec 22 2022) Mac OS 11.6, Apple MacBookPro M1 2020
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Svengali »

Hironori Takagi wrote: 03 Feb 2020, 05:32 I think common problem on using the George command is:
Use space key, double quotation, quotation (they are separator characters),
and automatically translation of string to number (for example, input "0001" become "1").

Here is my method:
・Use tv_ClipName instead of tv_ClipInfo to get ClipName
・Use xxx = CONCAT ("_", result) - stop automatically translation
・Use name = (CUT (xxx, 2, LEN(xxx))) - when outputting

Perhaps even this is not perfect.
Perhaps I wasn't clear about the bug I found. The tv_ClipInfo problem happens with any CLIP TITLE where the name contains one or more spaces. Since the parsing in tv_ClipInfo depends on spaces between the variables, the extra Clip Title spaces cause a mis-alignment resulting in the wrong CLIP information being inserted into the wrong CLIP variables.

The reason this matters is ANY SCRIPT THAT MANAGES MULTIPLE CLIPS, for instance ANY STORYBOARDING OUTPUT, could be filled with errors if the artist uses spaces in the Clip Titles. Could be a "hard to find" problem if this parsing bug isn't fixed.

I'm uploading a one-button panel with a button called tv_ClipInfo Parsing Bug Demo. Anyone who wants to see the problem can download this Bug Demo and immediately compare the results of CLIP TITLES, ONES THAT CONTAIN SINGLE WORD TITLES side-by-side with ONES THAT HAVE MULTIPLE WORDS AND SPACES IN THEIR TITLES. Compare the CLIP information that get placed and MISPLACED in the variables on CLIPS without spaces and with spaces.

sven
Clip Name Bug.png
Clip Name Bug.png (26.8 KiB) Viewed 16615 times
Attachments
tv_ClipInfo Bug demo.tvpx
(91 KiB) Downloaded 606 times
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
Hironori Takagi
Posts: 313
Joined: 14 May 2018, 10:15
Location: Tokyo, Japan
Contact:

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Hironori Takagi »

Alright.
As a solution to the problem that causes in scripts that need to pick up information from tv_ClipInfo,
I use tv_ClipInfo's exported string rule ("Name" clip-name-value "Iscurrent") to insert double quote.

Code: Select all

// pickup clip info
tv_ClipInfo
tempClipInfo = result
loop = 1
count = 1
last = LEN(tempClipInfo)
WHILE loop
	checkChar = CHAR(tempClipInfo,count)
	IF CMP(checkChar,"n") == 1
		checkWord = CUT(tempClipInfo,count,count+3)
		IF CMP(checkWord,"name") == 1
			tempClipInfoHead = CUT(tempClipInfo,1,count+4)
			headLength = LEN(tempClipInfoHead)
			tempClipInfoHead = CONCAT(tempClipInfoHead,'"')	// add " for include " "(space)
			tempClipInfoTail = CUT(tempClipInfo,count+5,last) 
			loop2 = 1
			count2 = 1
			last2 = last - headLength
			WHILE loop2
				checkChar = CHAR(tempClipInfoTail,count2)
				IF CMP(checkChar,"I") == 1
					checkWord = CUT(tempClipInfoTail,count2,count2+8)
					IF CMP(checkWord,"IsCurrent") == 1
						tempClipInfoMid = CUT(tempClipInfoTail,1,count2-2)
						tempClipInfoMid = CONCAT(tempClipInfoMid,'" ')
						tempClipInfoTail = CUT(tempClipInfoTail,count2,last2)
						tempClipInfo = CONCAT(tempClipInfoHead,tempClipInfoMid)
						tempClipInfo = CONCAT(tempClipInfo,tempClipInfoTail)
						loop = 0
						loop2 = 0
					END
				END
				count2 = count2 + 1
			END
		END
	ELSE
		IF CMP(count,last) == 1
			loop = 0
		END
	END
	count = count + 1
END
PARSE tempClipInfo name nameVAL IsCurrent IsCurrentVAL IsHidden IsHiddenVAL IsSelected IsSelectedVAL StoryboardStartFrame StoryboardStartFrameVAL FirstFrame firstFrameVAL LastFrame LastFrameVAL FrameCount frameCountVAL MarlIn MarkInVAL MarkOut MarkOutVAL ColorIdx ColorIdxVAL
Of course, I hope that it will be improved to the same result as tv_ProjectInfo.
TVPaint 11.7.2(Nov 14 2023), Windows11 Pro, HP Spectre x360 Convertible 14-ea0xxx / TVPaint 11.7.1(Dec 22 2022) Mac OS 11.6, Apple MacBookPro M1 2020
User avatar
Thierry
Site Admin
Posts: 2780
Joined: 07 Jan 2013, 08:28

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Thierry »

Added in the todo list.
Xavier
Posts: 1855
Joined: 01 Oct 2019, 11:08

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Xavier »

Done
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: CLIP NAME PARSE BUG in tv_ClipInfo command (with work-around)

Post by Svengali »

:D
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
Post Reply