Issue with tv_saveimage Topic is solved

A forum dedicated to George scripting questions
Post Reply
User avatar
my1ironlung
Posts: 20
Joined: 18 Sep 2013, 15:22

Issue with tv_saveimage

Post by my1ironlung »

Hello, I'm having trouble with saving an image to a specified local path. I get the error: "cannot open file."
I know that the path is valid because I am able to write a text file to the same location successfully, and I am also able to import images from the location with no trouble. Yet for some reason, I am not able to save an image here. The function I call is below:

Code: Select all

FUNCTION exportFrame()
  tv_SaveMode "PNG" "b32"
  tv_AlphaSaveMode NoPreMultiply

  fileName='"'"C:/Users/Harry T/Documents/tvpaintstuff/test/export/testFrame.png"'"'
  txtFile='"'"C:/Users/Harry T/Documents/tvpaintstuff/test/export/exist.txt"'"'
  
  tv_WriteTextFile "create" txtFile hello    //this works

  //print fileName                                     //this reads as "C:/Users/Harry T/Documents/tvpaintstuff/test/export/testFrame.png"
  tv_saveimage fileName                           //this throws the error: "cannot open file."
  
END
  
Thank you in advance.
Svengali
Posts: 1553
Joined: 28 Dec 2006, 10:08

Re: Issue with tv_saveimage

Post by Svengali »

Try going into Preferences... look under Interface option and check the box next to Never confirm. Then try function to save .png image.

Let me know if that works?

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
my1ironlung
Posts: 20
Joined: 18 Sep 2013, 15:22

Re: Issue with tv_saveimage

Post by my1ironlung »

Svengali wrote: 17 Mar 2019, 21:18 Try going into Preferences... look under Interface option and check the box next to Never confirm. Then try function to save .png image.

Let me know if that works?

Sven
unfortunately no that didn't change anything :?
Svengali
Posts: 1553
Joined: 28 Dec 2006, 10:08

Re: Issue with tv_saveimage

Post by Svengali »

Try this:
temp = "C:/Users/Harry T/Documents/tvpaintstuff/test/export/testFrame.png"
filename = '"' temp '"'
(where '"' means single/double/single quotes)
tv_SaveImage filename

also, whenever you ask for help, it's really a good idea to give details on your computer setup: Operating system, mem, version of TV_Paint, etc.

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
my1ironlung
Posts: 20
Joined: 18 Sep 2013, 15:22

Re: Issue with tv_saveimage

Post by my1ironlung »

OK I think I figured this out.

Some details:
TVpaint Pro 11.0.8 -64 bits for PC.
Running windows 8.1. I've also tried this on macOS 10.14

I don't think it is a permissions issue, since the text file is able to be created. Even if I run similar code with a path navigator, i get the same error.

HOWEVER, if I remove the extra quotes from the tv_saveimage path, it exports fine.

So it seems that writing a txt file requires the double quotes and the tv_saveimage needs no quotes. Code is below.

Code: Select all

FUNCTION exportFrames2()

  tv_getpath "home" //path par defaut
  srcFolder=result

  tv_readuserstring "ExportDigital" "folder" srcFolder
  srcFolder=result

  requester = FileRequester("<Select a file",srcFolder,srcFile,"*.txt")
  IF ( requester!=1 )
    EXIT
  ELSE
    END
    
  textName="123.txt"
  filename="123.png"
  saveTxt=concat(pathname, textname)
  saveTxtQuotes='"'saveTxt'"'
  PRINT "folder:" pathname                       				//prints correctly
  
  fullname=concat(pathname, filename)
  fullnameQuotes= '"'fullname'"'  // apply quotes here
  
  PRINT "fullname: " fullnameQuotes        				//prints correctly
  PRINT "textname: " saveTxtQuotes          				//prints correctly
  
  tv_WriteTextFile "create" saveTxtQuotes hello world 	//saves a .txt file correctly
  tv_saveimage fullnameQuotes						//throws error: "cannot open file."
   tv_saveimage fullname							//saves a .png file correctly.

END

Svengali
Posts: 1553
Joined: 28 Dec 2006, 10:08

Re: Issue with tv_saveimage

Post by Svengali »

Getting to the correct path and filename (that works) can open you up to several errors that might need solving.
from the George syntax page:
savefile syntax.png
First thing: as the docs say, if there is a "special character" you need to enclose (as part of the complete path-filename string) explicit double quote marks... and in your code first example, there is a subfolder named /Harry T/ in which the space after the y, counts as a special character. In your second code example I don't think there are any special characters included in the constructed path, so explicit double quote marks aren't required.

Second thing: Mac paths use forward slashes "C:/folder/subfolder/filename.ext" but Windows uses backward slashes C:\folder\subfolder\filename.ext". A simple way to avoid error message is to include the following test which assigns the proper slash character to a one-character Slash string, which can then be used to construct path/file strings on the fly, each time the script runs.

Code: Select all

	
tv_Version "ComputerOS"
OpSystem = result
IF CMP(OpSystem,"WIN32") || CMP(OpSystem,"WIN64")
	Slash = "\"
ELSE
	Slash = "/"	
END
I asked about info on your operating system because I suspected that wrong-way slashes might be the actual cause of the error message (not the enclosing quotes) in the first example.

Bottom line: however you solved the problem, if it works now... that's what matters. 8)

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
my1ironlung
Posts: 20
Joined: 18 Sep 2013, 15:22

Re: Issue with tv_saveimage

Post by my1ironlung »

Interesting. Based on your feedback I've done a bunch of tests and this is what my results conclude:

Regardless of whether or not there is a space in the specified path, the tv_saveimage command only exports without the double quotes, regardless of whether the path contains any spaces.
The command tv_WriteTextFile, however, does seem to adhere to the rule about double quotes for paths with special characters.

Also, the direction of the slash has no effect for me. Both forward slashes and backslashes seem to work fine on either operating system.
I've tested this on windows 8.1 and 10, and also Mac OS Mojave 10.14.3. I've tried this on two different computers so I don't think it is specific to my setup. So, I'd be curious to know if others find the same results.

George Script remains mysterious for me, but still incredibly useful. As you said, the important thing is that it now works, and I appreciate you taking the time to help me. :)
Svengali
Posts: 1553
Joined: 28 Dec 2006, 10:08

Re: Issue with tv_saveimage

Post by Svengali »

I confess I've never worked on a Mac. Consequently all my experience in that regard is second hand. Over the years I've posted various scripts that included save-to-disk operations to which Mac users reported scripted path problems... but we managed to find workaround solutions through trial and error and testing by some of those Mac users.

In a search thru old threads on the subject I found a comment from Ematecki (seasoned tv_paint coder) saying that all OS (Mac, Win, Android and Linux) accept the forward slash in path strings... I've never actually tested that myself - if you have time, maybe you can confirm. It could also be that current OS are forgiving with respect to whichever path slash is used???

Over the years (and TVPaint generational updates) GEORGE has been quite useful for customizing and enhancing so many things in TVPaint... and it continues to evolve with new functionality and bug fixes :D

Mike's flawless effort in creating the definitive commands and syntax reference page has been a tremendous help toward understanding how GEORGE works.

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