Question about layer batch operation

A forum dedicated to George scripting questions
Post Reply
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Question about layer batch operation

Post by Zetariver »

Question again today.
I always make lots of layers and I separate main color layers and shadow color layers.
Shadow layers are always supposed to have a word "shadow" in its layer name.
For example, names of my layers are something like this

arm_color_main
arm_color_shadow
leg_color_main
leg_color_shadow
body_color_main
body_color_shadow

And I have a question. Is it possible to change opacity of all layers whose layer name has a word "shadow" at once? If it's possible what function will do the trick? If I can do that via george script It will save tons of time.
User avatar
Paul Fierlinger
Posts: 8100
Joined: 03 May 2008, 12:05
Location: Pennsylvania USA
Contact:

Re: Question about layer batch operation

Post by Paul Fierlinger »

If you give all shadow layers the same layer color, all that needs to be done is to go up into the "Group" folder to the far left of the button with the word "New", select Display Current Group (assuming that a shadow layer is your current active layer). Then dim the transparency on that layer and all the other selected ones will follow.
Paul
http://www.slocumfilm.com
Desktop PC Win10-Pro -64 bit OS; 32.0 GB RAM
Processor: i7-2600 CPU@3.40GHz
AMD FirePro V7900; Intuos4 Wacom tablet
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Question about layer batch operation

Post by Zetariver »

It works, but I always use layer group to separate body parts, and it's easy to find where those layers are in layer panel,
like layer group Red for head,layer group Blue for body, layer group Green for arms,etc etc.
Anyway, thank you for your advice.
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

Code: Select all

PARAM none

loop= 1
i= 0
WHILE loop
	tv_LayerGetID i
	curLID= result	
	IF CMP(curLID,"NONE")==0		
               tv_layerSet curLID
               tv_LayerInfo
               PARSE result layerDisplay layerPosition layerOpacity layerName layerType layerStart layerEnd layerPrelighttable layerPostlighttable layerSelection
               var(3) = none
               // PLEASE NOTICE WE USE NEWPARSE
               NewParse(layerName,"_")
               IF CMP(var(3),"shadow")==1
               	tv_LayerDensity 25
               END
               
		i= i+1	
	ELSE		
		loop=0
	END
END

Here is a script there set the Opacity to 25 if the 3rd part of the name is "shadow"
To find the 3rd part I use the function NewParse.
http://wiki.tvpaint.fr/index.php?title= ... divider.29
To make use of this you have to include the basic and advanced functions found here
http://wiki.tvpaint.fr/index.php?title= ... es_:_Basic
http://wiki.tvpaint.fr/index.php?title= ... :_Advanced
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Question about layer batch operation

Post by Zetariver »

Thank you. It looks great. Thank you for your effort.
But, I get this error

Execution ERROR
NewParse(layerName,"_")

NewParse function won't work correctly. What it the problem?
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

As I wrote you need to include the basic and advanced procedures which i linked to in my previous post,
You can read about inclusion here
http://wiki.tvpaint.fr/index.php?title=George#INCLUDE
You can read about procedures here
Http://wiki.tvpaint.fr/index.php?title= ... Procedures

That means the newparse procedures wont work unless you make it availeble in your scrpit either simple by copy and paste the prcefure at the end of the script together with the other procedures which newparse is dependable of . Or by having the procedures in a file and then include the file in your scipt with an include comand at the end.
-Mads
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Question about layer batch operation

Post by Zetariver »

madsjuul wrote:That means the newparse procedures wont work unless you make it availeble in your scrpit either simple by copy and paste the prcefure at the end of the script together with the other procedures which newparse is dependable of . Or by having the procedures in a file and then include the file in your scipt with an include comand at the end.
-Mads
Oh sorry. I thought newparse works independently and added function newparse alone. It works fine now. Thank your.
And I tried to include advanced.grg and basic.grg, but it won't work(so I added newparse function to your script.).
I got this error

ERROR: main program can't be truncated
OK

and

LINE XX
ERROR: undeterminated main program limits.
#INCLUDE "my script path"
OK

LINE XX is the end line number where I put #include.
It seems #include can't work correctly.What should I do to work it?
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

Zetariver wrote: Oh sorry. I thought newparse works independently and added function newparse alone.
If you examine the NewParse Procedure You will see that the FIND() Procedure (I highlighted it with red) is not part of the native procedures
http://wiki.tvpaint.fr/index.php?title= ... _Reference
So you would have to add is as well. to make it work. I think the rest of the functions CMP CUT and LEN is native

FUNCTION NewParse(string,divider)
LOCAL pos i workstr size
i = 0
pos = 1
workstr = string

IF ((CMP(workstr,"") == 0) && (CMP(divider,"") == 0) && (CMP(workstr,divider) == 0))
WHILE ((pos = Find(workstr,divider,1)) > 0)
IF ((pos != 1) && (pos != LEN(workstr)))
i = i+1
var(i) = CUT(workstr,1,pos-1)
workstr = CUT(workstr,pos+1,LEN(workstr))
ELSE
IF (pos == 1)
IF (pos != LEN(workstr))
workstr = CUT(workstr,2,LEN(workstr))
ELSE
workstr = ""
END
ELSE
workstr = CUT(workstr,pos,LEN(workstr))
END
END
END
if (CMP(workstr,0) == 0)
i = i+1
var(i) = workstr
END
END
RETURN i
END
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

Zetariver wrote: It seems #include can't work correctly.What should I do to work it?
Always put #include at the end of the script

But start with making a smiple include script
Somthing like this containing only one script

Code: Select all

FUNCTION sayHello()
	tv_warn "Hello World"
END
then save it in a file called function.grg
then make another script like this

Code: Select all

PARAM none
sayHello()

#INCLUDE "functions.grg"
and save it to another file called helloWorld.grg
and if works start adding functions from advanged.grgr og Basic-grg to the functions.grg script
and see if it at some point breaks

-Mads
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Question about layer batch operation

Post by Zetariver »

I checked and helloWorld.grg works fine, so my path setting is right.

I put NewParse and Find functions together this way and named it "test.grg" and included it in your script and it works fine.

Code: Select all

FUNCTION Find(string,car,start)
	LOCAL i size
	i = start
	size = LEN(string)
	
	IF ((start <= 0) || (start > size) || (CMP(car,"") == 1))
		RETURN -1
	END
	DO
		IF (CMP(CHAR(string,i),car) == 1)
			RETURN i
		END
	UNTIL ((i=i+1) > size)
	RETURN 0
END



FUNCTION NewParse(string,divider)
	LOCAL pos i workstr size
	i = 0
	pos = 1
	workstr = string
	
	IF ((CMP(workstr,"") == 0) && (CMP(divider,"") == 0) && (CMP(workstr,divider) == 0))
		WHILE ((pos = Find(workstr,divider,1)) > 0)
			IF ((pos != 1) && (pos != LEN(workstr)))
				i = i+1
				var(i) = CUT(workstr,1,pos-1)
				workstr = CUT(workstr,pos+1,LEN(workstr))
			ELSE
				IF (pos == 1)
					IF (pos != LEN(workstr))
						workstr = CUT(workstr,2,LEN(workstr))
					ELSE
						workstr = ""
					END
				ELSE
					workstr = CUT(workstr,pos,LEN(workstr))
				END
			END
		END
		if (CMP(workstr,0) == 0)
			i = i+1
			var(i) = workstr
		END
	END
	RETURN i
END

but if I separate them like this

basic.grg

Code: Select all

FUNCTION Find(string,car,start)
	LOCAL i size
	i = start
	size = LEN(string)
	
	IF ((start <= 0) || (start > size) || (CMP(car,"") == 1))
		RETURN -1
	END
	DO
		IF (CMP(CHAR(string,i),car) == 1)
			RETURN i
		END
	UNTIL ((i=i+1) > size)
	RETURN 0
END
advanced.grg

Code: Select all

FUNCTION NewParse(string,divider)
	LOCAL pos i workstr size
	i = 0
	pos = 1
	workstr = string
	
	IF ((CMP(workstr,"") == 0) && (CMP(divider,"") == 0) && (CMP(workstr,divider) == 0))
		WHILE ((pos = Find(workstr,divider,1)) > 0)
			IF ((pos != 1) && (pos != LEN(workstr)))
				i = i+1
				var(i) = CUT(workstr,1,pos-1)
				workstr = CUT(workstr,pos+1,LEN(workstr))
			ELSE
				IF (pos == 1)
					IF (pos != LEN(workstr))
						workstr = CUT(workstr,2,LEN(workstr))
					ELSE
						workstr = ""
					END
				ELSE
					workstr = CUT(workstr,pos,LEN(workstr))
				END
			END
		END
		if (CMP(workstr,0) == 0)
			i = i+1
			var(i) = workstr
		END
	END
	RETURN i
END
and include those basic.grg and advanced.grg, that same error message pops up,
saying "undeterminated main program limits".
I think those basic.grg and advanced.grg does not reference each other's functions?
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

I came to thinbk of maybeyou can't include 2 include scripts at one point.
This will not work

Code: Select all

PARAM none
sayHello()

#INCLUDE basic.grg
#INCLUDE advanced.grg
But years ago I collected the two files basic and Advanced in one file so I have not had this problems
-Mads
Zetariver
Posts: 77
Joined: 23 Dec 2013, 07:58

Re: Question about layer batch operation

Post by Zetariver »

I didn't know 2 include does not work. Thank you for checking it.
Anyway, thank you for your script again.
I will use your nice opacity control script.
Your script teaches me how to handle layer elements in TVPaint and It will save tons of time for me.
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

You are welcome. Glad I could help.
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Question about layer batch operation

Post by Mads Juul »

I can see it has been discussed before
http://forum.tvpaint.com/viewtopic.php? ... ude#p29015
Post Reply