"Save As" script retaining the name

Corel Paint Shop Pro

Moderator: Kathy_9

Post Reply
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

"Save As" script retaining the name

Post by df »

Hey, I have a script I'm trying to figure out. I've seen a few mentions on here on how to get the script to as the program for the name then apply that name to the "Save As" part of the script. But the more I read (and try) the less I understand. Here's the code I have

Code: Select all

# FileSaveAs
    App.Do( Environment, 'FileSaveAs', {
            'Encoding': {
                'JPG': {
                    'Variant': App.Constants.JpegFormat.Standard, 
                    'CompressionFactor': 1, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1, 
                    'EXIF': True, 
                    'EmbedJPGICC': True
                    }
                }, 
            'FileName': u'C:\\Users\\Dan\\Pictures\\Scans\\Finals\\Image1.jpg', 
            'FileFormat': App.Constants.FileFormat.JPG, 
            'FormatDesc': u'JPG JPEG ', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 
                'Version': ((13,0,0),1)
                }, 
            'DefaultProperties': []
            })

What I'm doing is scanning some 16 moving cases packed full of 35mm slides. I'm scanning 4 slides at a time, then using PSP to "crop to image". Then I auto adjust, sharpen, and save. The rub is that since my scanner's "Transparency Media Adapter" consists of a "guide" that you lay on the scanner glass and it doesn't lock in anywhere and the slides just sit in the holes in the TMA (loosely) I can't just crop with a script.
Image
I need to align each one to crop it since as you can see each frame isn't exactly locked into the same spot.
Image
This is what comes into PSP, I then crop to image 4 times. That gives me 4 images (Image 1, Image 2, etc...). But they aren't saved yet, so there is no original name (unless you can consider Image 1 is the name). I also need to be able to do whatever else to each image as needed (some are dustier than others even after cleaning the slide before scanning). But the one hang up that I have is that stupid name thing staying the same.

Thanks in advance
Dan
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: "Save As" script retaining the name

Post by df »

And I'm using PSP X3 with service packs 1-5 installed.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
Cassel
Posts: 1587
Joined: Fri Oct 29, 2010 6:49 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Corel programs: PSP 8 (JASC) to PSP 2023
Location: Canada
Contact:

Re: "Save As" script retaining the name

Post by Cassel »

Why do you need a script? Are you trying to do that in batch mode? If the file was never saved, where do you expect the script would retrieve a name? In the code you posted, it will be named Image1, but the second one will ALSO be named Image1 because that is what is in the name. Would you want them to be named Image1, Image2, Image3 and so on? This might be codeable but if you want to have totally different name, then you might need to do it manually.
Cassel
https://creationcassel.com/store
Specializing in PSP specific products: scripts and tubes

https://scrapbookcampus.com
for beginner and seasoned scrappers and designers and other PSP users
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: "Save As" script retaining the name

Post by LeviFiction »

I'm with Cassel, I don't really see the point in a script to save each of these images. But hey if you want to then I'll do my best to help.

App.TargetDocument.Title

Inside of PaintShopPro there is an App object. This App object has a few commands and a lot of variables applied to it. Two of those variables apply to an open image object

TargetDocument - the image that had focus when you ran the script

ActiveDocument - the image that currently has focus during the running of the script this can change dynamically.

And each document as its own set of variables for example "Name" and "Title"

"Name" holds the entire name of the file including path and extension. "C:\Users\User\My Pictures\image1.jpg" But if the image doesn't have a filename yet then this variable is empty.

"Title" hold only the title on the image title-bar. Now, if the file has a filename this will also include the file extension. If it doesn't, like your images don't, it'll need a file extension.

So you're looking for App.TargetDocument.Title.

Now this is the part of the code you're concerned with.

Code: Select all

            'FileName': u'C:\\Users\\Dan\\Pictures\\Scans\\Finals\\Image1.jpg',
            'FileFormat': App.Constants.FileFormat.JPG,
            'FormatDesc': u'JPG JPEG ', 
So you what you want to do is replace " u'C:\\Users\\Dan\\Pictures\\Scans\\Finals\\Image1.jpg'," with "App.TargetDocument.Name + u'.jpg',"

Code: Select all

            'FileName': App.TargetDocument.Name + u'.jpg',
            'FileFormat': App.Constants.FileFormat.JPG,
            'FormatDesc': u'JPG JPEG ', 

Since PSP auto-updates the number at the end of the image name you should get a different image name every time you save....unless you're doing this between sessions of PSP then you're screwed.

Also if you don't specify a very specific path it'll just save to the last location it saved so it won't save in the same folder as the image you just opened.

Now if you want to be able to give a base-name and have PSP auto-increment that name for you that's a whole other ballpark.
https://levifiction.wordpress.com/
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: "Save As" script retaining the name

Post by df »

Code: Select all

# FileSaveAs
    App.Do( Environment, 'FileSaveAs', {
            'Encoding': {
                'JPG': {
                    'Variant': App.Constants.JpegFormat.Standard, 
                    'CompressionFactor': 1, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1, 
                    'EXIF': True, 
                    'EmbedJPGICC': True
                    }
                }, 
            'FileName': App.TargetDocument.0000 + u'.jpg',
            'FileFormat': App.Constants.FileFormat.JPG,
            'FormatDesc': u'JPG JPEG ', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 
                'Version': ((13,0,0),1)
                }, 
            'DefaultProperties': []
            })
If this saves I can't find where it does.


P.S.: This is just the tail end of the script, not the entire script. I'm not making a script that duplicates what another button does, I was just displaying the part of the script that seemed relevant.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: "Save As" script retaining the name

Post by LeviFiction »

Can I assume you didn't understand that "App.TargetDocument.Title" was the variable and not an invitation for you to write your own name?

App.TargetDocument.Title is a variable that holds the text that is shown in the tab or title bar of the image. So if your image says "Image2" then App.TargetDocument.Title returns "Image2" if the title of the image is "Cars.jpg" App.TargetDocument.Title returns "Cars.jpg."

So why you're using App.TargetDocument.0000 I really don't understand since 0000 is not a property of a document.

And it should default to the last saved directory so if you saved your last image in "C:\Users\User\My Pictures" it'll save there if you last saved in "C:\Users\User\My Documents\" then it'll save there. Where ever the last saved image was saved is where you should find the image. The only potential problem is that the image might not have saved at all because you used "App.TargetDocument.0000" which, again, doesn't exist.
https://levifiction.wordpress.com/
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: "Save As" script retaining the name

Post by df »

OK, the code you gave, copied and pasted, just recorded a jpeg with nothing for a name and any future uses of the script records over that with the new jpeg with no name. I guess that's why I tried the 0000 part hoping it would add to it if it had something to begin with. I've tried so many different things I'm getting mixed up. As a matter of fact you can go ahead and assume that this is as much a foreign language to me as anything. Greek makes more sense, and that's saying something.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: "Save As" script retaining the name

Post by LeviFiction »

Haha, I had to actually learn how to use Python before I started getting into scripting because I wanted to understand how the language itself worked with PSP so I understand quite well how it's like a foreign language.

The big problem with what you want to do is that if you want the program to automatically choose a name that doesn't already exist by incrementing the value in the name you have to have Python read all of the files in the saving directory and then choose a value that doesn't exist by comparing it against all of the other options. As far as I know there is no command in Python to do that automatically. I could be wrong but as of yet I have not come across one.

So if you really wanted to get this done you'd either have to do a lot of work yourself or look for a Python library that offers that functionality to you.

Otherwise the easiest method is to just save each image individually, does it take a little longer? Yes but ultimately offers you the most control.
https://levifiction.wordpress.com/
Post Reply