Using #INCLUDE inside embedded script

A forum dedicated to George scripting questions
Post Reply
spyderheart
Posts: 124
Joined: 22 Jan 2013, 03:11

Using #INCLUDE inside embedded script

Post by spyderheart »

Hi all,
I'm trying to use #INCLUDE "file.grg" from inside an embedded george script in a custom panel. It works fine as long as I provide the full path for "file.grg" (e.g. "/Users/Me/Library/tvp animation 11/default/george/file.grg").
The problem is that I am trying to create something that can be shared as a TVPX, so hard-coding the full path is not an option since it will be different on every system. I know that TVPaint looks for the file path relative to the path of the main executing script. However, in the case of an embedded script inside of an action, it's pretty unclear what the main path is... so I need to determine the full path.

It seems like I should be able to get there using

Code: Select all

tv_getpath CONFIG
path = result"/george/myscriptfolder/file.grg"
#INCLUDE path
But then it seems that #INCLUDE doesn't accept a variable string.

So what are my options folks?
Much appreciated,
David
David
--------------------------------------------------------
TVPaint 11.7 Standard
System: 64GB RAM // 3 TB SSD // Core i7 8700K // NVIDIA GTX 1080// Windows 10 Home
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Using #INCLUDE inside embedded script

Post by Svengali »

spyderheart wrote: 20 Jan 2018, 23:20 Hi all,
I'm trying to use #INCLUDE "file.grg" from inside an embedded george script in a custom panel. It works fine as long as I provide the full path for "file.grg" (e.g. "/Users/Me/Library/tvp animation 11/default/george/file.grg").
The problem is that I am trying to create something that can be shared as a TVPX, so hard-coding the full path is not an option since it will be different on every system. I know that TVPaint looks for the file path relative to the path of the main executing script. However, in the case of an embedded script inside of an action, it's pretty unclear what the main path is... so I need to determine the full path.

It seems like I should be able to get there using

Code: Select all

tv_getpath CONFIG
path = result"/george/myscriptfolder/file.grg"
#INCLUDE path
But then it seems that #INCLUDE doesn't accept a variable string.

So what are my options folks?
Much appreciated,
David
Just some speculation, I haven't tested any of the following...

1. I think the content of the #Include file is appended to the main script AFTER the main script is called but BEFORE any of the commands in the main script are executed... in other words, I suspect that the path you construct using the tv_GetPath command in the main script doesn't get constructed until after the main program attempts to include the contents of the #include file. (its like a chicken/egg problem).

I'm pretty sure that is why your pre-defined full path works but a generated full path does not.


2. You might be able to Jury-rig something by using several scripts in tandem...
a. the first script solves a custom, full path and appends it as a final line - replacing a dummy line - with a full path #include file line, to a second, existing script. Then the first script calls...
b. the second script using tv_RunScript. Like they say in the movies, "just crazy enough it might work!"



3. A word of caution on using any data stored in the "default" folders, for instance:
/Users/Me/Library/tvp animation 11/default/george/file.grg
I'm pretty sure all that data is from your LAST TVPaint session. All current data is mainained in TVPaint memory as it is continually updated while TVPaint is running.

When you quit TVPaint, the new data is stored in the default folders. Pulling data stored in the default folders might or might not be valid.

luck, 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
spyderheart
Posts: 124
Joined: 22 Jan 2013, 03:11

Re: Using #INCLUDE inside embedded script

Post by spyderheart »

Thanks Sven,
I've come up with a work around and would love to know what you think before I release it into the wild:
My purpose for putting the #include inside the embedded script was to use the same functions in each button (functions inside the "file.grg") while having different buttons pass different arguments to the functions. So for a complete picture, if file.grg looks like this

Code: Select all

PARAM none
tv_nop
EXIT
FUNCTION doStuff(X)
//stuff...
tv_warn X
RETURN
END
The following would be the embedded script of a button:

Code: Select all

doStuff("I feel INCLUDED!")
#INCLUDE "file.grg"
another button might have

Code: Select all

doStuff("I feel EMBEDDED!")
#INCLUDE "file.grg"
etc...

Since it is really only to pass an argument to a function I don't want to put directly inside the action and it looks like #INCLUDE is sketchy at best for a shareable tvpx - i turn to the userstring and tv_runscript. file.grg gets modified:

Code: Select all

PARAM none
tv_readuserstring "MyScriptSettings" "VariableString"
doStuff(result)
EXIT
FUNCTION doStuff(X)
//stuff...
tv_warn X
RETURN
END
and the embedded script now looks like:

Code: Select all

tv_writeuserstring "MyScriptSettings" "VariableString" "I might just be crazy enough to work!" //define string value specific to the button where this is embedded
tv_getPath config
tv_runscript result"george/file.grg"
Basically I am passing the argument to the desired function via the user string. Make sense? Can you see any reason this wouldn't work as a shared tvpx?
One more step must be taken to ensure the script are actually installed where they are needed. In another action I would add a command:

Code: Select all

tv_writeuserstring "MyScriptSettings" "" 
to reset the variable string to null. and then add a "Set Script" command that points to "file.grg" to ensure that the tvpx export grabs it. Of course pushing that dummy button would simply do nothing.

One more thing I wanted to ask:
A word of caution on using any data stored in the "default" folders, for instance:
/Users/Me/Library/tvp animation 11/default/george/file.grg
I'm pretty sure all that data is from your LAST TVPaint session. All current data is mainained in TVPaint memory as it is continually updated while TVPaint is running.
If the user has just installed my tvpx, can count on file.grg being found in the george folder - assuming I've taken the precaution described above? Should I ask them to restart TVPaint?

This was a long one. Thanks for reading!
David
--------------------------------------------------------
TVPaint 11.7 Standard
System: 64GB RAM // 3 TB SSD // Core i7 8700K // NVIDIA GTX 1080// Windows 10 Home
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Using #INCLUDE inside embedded script

Post by Svengali »

I've experimented with variations on the things you proposed but could not get an "on-the-fly" #Include file to work. I did create a simple button/script that tests where the GEORGE subfolder is located and the resulting complete path was the same as I find anytime I use the tv_GetPath GEORGE command in a saved script:
GeorgePath = C:\Program Files\TVPaint Developpement\TVPaint Animation 11 Pro (64bits)\george\

Based on that, I created an Embedded script using a hard-coded complete path to a GEORGE subfolder #Include file, and found I could make effective calls to the functions included there. So it seems possible to have one #Include file that could serve all button/scripts' #Include calls.

But my hard-coded complete path for my TVPaint installation would not work with someone else'sTVPaint 11 standard version or any earlier versions of TVPaint standard or pro.

Conclusion: there might be a way to do what you want, but I couldn't find a general solution... if you ever get one working I'd like to see the button/scripts and test it out. :D

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
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Using #INCLUDE inside embedded script

Post by NathanOtano »

Svengali wrote: 22 Jan 2018, 23:53 I've experimented with variations on the things you proposed but could not get an "on-the-fly" #Include file to work. I did create a simple button/script that tests where the GEORGE subfolder is located and the resulting complete path was the same as I find anytime I use the tv_GetPath GEORGE command in a saved script:
GeorgePath = C:\Program Files\TVPaint Developpement\TVPaint Animation 11 Pro (64bits)\george\

Based on that, I created an Embedded script using a hard-coded complete path to a GEORGE subfolder #Include file, and found I could make effective calls to the functions included there. So it seems possible to have one #Include file that could serve all button/scripts' #Include calls.

But my hard-coded complete path for my TVPaint installation would not work with someone else'sTVPaint 11 standard version or any earlier versions of TVPaint standard or pro.

Conclusion: there might be a way to do what you want, but I couldn't find a general solution... if you ever get one working I'd like to see the button/scripts and test it out. :D

Sven
I guess that way we could go search scripts in the script folder of the configuration instead of the installation folder? Recreating the path depending on the computer path and where the config folder is. Could permit indeed to share a config between multiple computers/drives
It's not directly linked to the problem here but it solves mine : sharing my config synced on multiple computers but avoiding embedding scripts. Right now I lose the links to my scripts on the panels that have buttons linked to scripts (panels that are not exported/imported).

Including a script when sharing a panel doesn't make sense for me, cause you either embed the script or upload it on the panel so it's zipped with it while shared. Including on a button could be nice when working but sharing it and making it work seems difficult to me cause there is no reason somebody has the same scripts than you in his computer, let alone at the same place. Maybe on some shared network in a company it could be possible but not across the internet on people unrelated I guess
But for coding purposes maybe having each included script exported with the panel as a new feature could be great.
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