creating a shortcut key to toggle through a List

Share your custom panels, brushes, papers... (you need to be registered to read posts in this section)
Post Reply
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

creating a shortcut key to toggle through a List

Post by Svengali »

Here is a simple way to create a new button (and shortcut key) that lets you toggle through a list of Main Panel tools - in this case, you can toggle the four different stroke types.

Do the following steps:
Part 1 - creating the button
1. Select and copy the script in the box below - all of it, as is.
2. create a new button in a panel and give it a name (I called mine ToggleList). Remember the panel's name too.
3. Edit the button and add a new command line by clicking on "Embedded George Script"
4. Paste the script you just copied into the window titled "Type Script's Command"
5. Press OK to close the script window and Press OK to close the button Editor.

Part 2 - assigning a shortcut key to the button
1. Press Control-K to open the Keyboard ShortCuts dialog window.
2. Pick a shortcut key.
3. Search for the button you just created which will be under the panel's name in the list. Example: "MyPanel:ToggleList"
4. Press Assign, then save by pressing OK

The new shortcut key should cycle you through all four stroke options/icons.

Additional ToggleLists for the Main Panel tools could be made by collecting an exact list of the option titles you want to toggle through and customize the embedded scripts in other buttons.

The ToggleList could also toggle ACROSS tool categories - for example all the various FILL options could be cycled through: Filled Stroke, Filled Line, Filled Rectangle, Filled Circle, Filled 2 Pts Circle, Filled 3 Pts Circle, etc.

Other kinds of ToggleLists could be created but the code lines which test the current state would have to be different.

Code: Select all

// ToggleList.grg
// Svengali - Sept. 15, 2009
// Toggling or cycling through the four Stroke types

Param none
ScriptName = 'ToggleList'



option1 = "singledot"
option2 = "dot"
Option3 = "freehandline"
option4 = "freehandfill"


tv_GetActiveShape
parse result Shape

IF CMP(Shape, Option1)==0 && CMP(Shape, Option2)==0 && CMP(Shape, Option3)==0 && CMP(Shape, Option4)==0 
        tv_SetActiveShape Option1
END

IF CMP(Shape,Option1)
	tv_SetActiveShape Option2
END
IF CMP(Shape,Option2)
	tv_SetActiveShape Option3
END
IF CMP(Shape,Option3)
	tv_SetActiveShape Option4
END
IF CMP(Shape,Option4)
	tv_SetActiveShape Option1
END
This example also demonstrates the power of the Embedded Script feature in the Button Editor. I like it.
Sven

EDIT - (added a test to see if NONE of the four stroke tools were selected and if not then selects stroke Option1.)
Last edited by Svengali on 17 Sep 2009, 13:12, edited 5 times in total.
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: creating a shortcut key to toggle through a List

Post by KenC »

Thanks Sven :)

Great little framework to expand on. Now I just need to read up on the functions that writes to the ini files and write out the last state of the buttons in each toggle script and I can have more than one toggle script that remembers what tool was selected. This will help to slim down my mess of shortcuts.

I've been using ultraedit to write george stuff in, that new inline script editor is pretty nice.
There's no place like ~/
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: creating a shortcut key to toggle through a List

Post by Svengali »

Ken, I added a line to the original listing that tests to see if NONE of the Stroke tools is current, and if so, it sets the current tool to Option1. This obviates the need to store the state of anything at all.

When adding other buttons for different sets of tools, each button's script would start off with a similar test to see if the current tool is one of that particular button's set and if not then just set the current tool to Option1 of the its set. Each subsequent press of the button will cycle to the next Option in the set and so on.

Sven
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: creating a shortcut key to toggle through a List

Post by KenC »

There's a small typo in there, was driving me crazy for a while until I spotted it :)

IF CMP(CurrentShape,Option1)
tv_SetActiveShape Option2
END

Should be:

IF CMP(Shape,Option1)
tv_SetActiveShape Option2
END

Realy nice to be able to group tools and toggle trough them, I'm so used to that from photoshop. I've made all my selection tools in one group, all my drawing tools in another and so forth. Frees up lots of keys for other stuff.
There's no place like ~/
User avatar
Sewie
Posts: 1310
Joined: 18 Jun 2008, 11:57
Location: The Netherlands, Europe
Contact:

Re: creating a shortcut key to toggle through a List

Post by Sewie »

Sounds interesting , guys. I'm going to give it a try soon, even though I'm a complete noob with those script features...
Michael Sewnarain - Website
Windows 11/64b Pro - TVP11.7.0 & 11.7.1 - Pro/64b - Cintiq32 Pro - Intel i7-12700K - 64Gb RAM
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: creating a shortcut key to toggle through a List

Post by Svengali »

Ken,
Sorry for the typo, I simplified the variable name from CurrentShape to Shape and just missed that one.

After thinking a bit more I noticed a little neater way to code it...

Code: Select all

Param none
ScriptName = 'ToggleList'

option1 = "singledot"
option2 = "dot"
Option3 = "freehandline"
option4 = "freehandfill"


tv_GetActiveShape
parse result Shape


IF CMP(Shape,Option1)
	tv_SetActiveShape Option2
	EXIT
END
IF CMP(Shape,Option2)
	tv_SetActiveShape Option3
	EXIT
END
IF CMP(Shape,Option3)
	tv_SetActiveShape Option4
	EXIT
END
tv_SetActiveShape Option1    // if all else fails we want Option1, especially the first time it's clicked

Storing Variables in the config.ini file
Also, if you want to store and retrieve sets of variables in the config.ini file, it's easy. The two commands are:
tv_WriteUserString Section Line Text
tv_ReadUserString Section Line Default

With each Write you are creating a group entry, identifying it first by its Section (unique group name), its Line (unique identifier for each stored value) and the actual string of text stored there.

Var1="third rock"
Var2=4
Var3=""
tv_WriteUserString "SolarSystem" "Earth" Var1
tv_WriteUserString "SolarSystem" "Mars" Var2
tv_WriteUserSTring "SolarSystem" "Venus" Var3

creates this config.ini entry:
[SolarSystem]
Earth=third rock
Mars=4
(note that Venus never gets written)

Then, with each Read command you get back what was stored... or if nothing was stored and the line identifier can't be found, it returns the Default instead.

tv_ReadUserString "SolarSystem" "Earth" "nul"
parse result Var1
tv_ReadUserString "SolarSystem" "Mars" "nul"
parse result Var2
tv_ReadUserString "SolarSystem" "Venus" "nul"
parse result Var3

returns:
Var1 contains "third rock"
Var2 contains 4
Var3 contains "nul"

Try a simple Write/Read test - then exit TVPaint (which updates the config.ini file) and search the config.ini for the Group Section and you'll see something like the above. Advice is to use config.ini space sparingly.
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: creating a shortcut key to toggle through a List

Post by KenC »

Yeah that's a lot cleaner, when having lots of tools to toggle that first test gets realy long. I already made a bunch of togglescripts but I'll use the new version from now on.

Thanks for the info on the ini files.

With toggle scripts like this it would be super if george could fire of tvpaint shortcuts. That way you could create a bunch of brushes from within tvpaint which then gets a shortcut if you name them. Then you could create a toggle script that switched through your brushes by the shortcut names. It would get realy complicated to build each brush from george commands and then toggle through them.

Something like:

tv_playshortcut "KenCBrushes:graphitebrush"

Where "graphitebrush" is a sampled brush in a palette called "KenCBrushes"
There's no place like ~/
Post Reply