Save as procedure
Moderator: Kathy_9
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Save as procedure
Hello,
I need to add a "Save As" procedure to a script, where the name of the specific file will be kept intact (each file will have its own name.) and the word "INTERNET" placed ahead of the name of the file.
Thanks for the info
Bert
Using Windows 7 Professional
PaintShop Pro 2018
I need to add a "Save As" procedure to a script, where the name of the specific file will be kept intact (each file will have its own name.) and the word "INTERNET" placed ahead of the name of the file.
Thanks for the info
Bert
Using Windows 7 Professional
PaintShop Pro 2018
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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 procedure
You have to be comfortable with adding code to your script manually. Scripts in PSP are written in the Python programming language since they are plain text files they can be edited in regular Notepad or more advanced code editors. My preferred editor is notepad++.
If you're already familiar with Python Read this:
PSP includes a number of easy built-in variables that can help. I would recommend using the built-in variables App.TargetDocument.Name and App.TargetDocument.Title. Name is the full path of the file. Title is the filename. You can use the os library on Name to split the various parts of the filename apart or you can use the very simple rstrip and split functions.
IF you have no idea what I'm talking about read this:
Python is what's known as a "white-space aware" or "White-space sensitive" language. In other words it uses spaces, tabs, and the like to determine which parts of the program belong to each other. This also means you have to match the kind of spacing used on each line when you indent. By default PSP uses 4 spaces for each indentation. Do not use tabs when writing in the code I'm going to demonstrate for you. Always use spaces. If you don't match the indentation you'll get errors when trying to run your script.
First, record the script you want to use. If the only thing in your script is the SaveAs function that's fine. It's simply faster and easier to record the script first as PSP does all of the heavy lifting with making sure the settings are correct.
Once you've recorded and saved your script hit the "Edit Script" button on the script toolbar. This will tend to look like pencil writing on a piece of paper. It should open up the Script Editor where you can see the AUthor, Copyright, Description, and all of the commands in the script. Each command has a checkbox, a dropdown and the name of the command. FInd "FileSaveAs" and change the dropdown from Default to Interactive. This will force the script to always pop-open the dialog even when you have the script running as silent. If you don't want this you can leave it at Default, this will run the command interactively or silently depending on how you have your script execution set on your toolbar. Or Silent will always run the code silently. With no input from you.
Once you've made the change hit Save.
Next, with the script editor still open hit the "Text Editor" button and it'll open your script in notepad.
You're looking to add your new code to the top of the program right underneath this line
This means your code will be the first indented line. Remember we need 4 spaces to match the indent that PSP uses when it writes the script.
Next you'll add these 2 lines of code
Finally you'll need to change one last line of the script. You're looking for a line that looks like this
You want to replace the portion between the ":" and the "," in this case that's "u'C:\\users\\Username\\Photos\\photoname.jpg'" or whatever you saved your file as. We'll replace it with the variable name "filename" like this
Now save the script, you'll want to make sure you move the script into your scripts-trusted folder.
Scripts by default are saved to scripts-restricted, this folder is for scripts that do simple things and don't need any permissions to your computer to run. Because you're saving a file you need to have it in scripts-trusted. These folders are usually in "C:\\users\\Username\\Documents\\Corel PaintShop Pro\\2018\\Scripts-Restricted" and "C:\\users\\Username\\Documents\\Corel PaintShop Pro\\2018\\Scripts-Trusted"
Here is a video demonstrating the process, I don't normally do this as they tend to be very long videos:
https://drive.google.com/file/d/1w4HOZW ... Ft1s6/view
If you're already familiar with Python Read this:
PSP includes a number of easy built-in variables that can help. I would recommend using the built-in variables App.TargetDocument.Name and App.TargetDocument.Title. Name is the full path of the file. Title is the filename. You can use the os library on Name to split the various parts of the filename apart or you can use the very simple rstrip and split functions.
IF you have no idea what I'm talking about read this:
Python is what's known as a "white-space aware" or "White-space sensitive" language. In other words it uses spaces, tabs, and the like to determine which parts of the program belong to each other. This also means you have to match the kind of spacing used on each line when you indent. By default PSP uses 4 spaces for each indentation. Do not use tabs when writing in the code I'm going to demonstrate for you. Always use spaces. If you don't match the indentation you'll get errors when trying to run your script.
First, record the script you want to use. If the only thing in your script is the SaveAs function that's fine. It's simply faster and easier to record the script first as PSP does all of the heavy lifting with making sure the settings are correct.
Once you've recorded and saved your script hit the "Edit Script" button on the script toolbar. This will tend to look like pencil writing on a piece of paper. It should open up the Script Editor where you can see the AUthor, Copyright, Description, and all of the commands in the script. Each command has a checkbox, a dropdown and the name of the command. FInd "FileSaveAs" and change the dropdown from Default to Interactive. This will force the script to always pop-open the dialog even when you have the script running as silent. If you don't want this you can leave it at Default, this will run the command interactively or silently depending on how you have your script execution set on your toolbar. Or Silent will always run the code silently. With no input from you.
Once you've made the change hit Save.
Next, with the script editor still open hit the "Text Editor" button and it'll open your script in notepad.
You're looking to add your new code to the top of the program right underneath this line
Code: Select all
def Do(Environment):
Next you'll add these 2 lines of code
Code: Select all
path = App.TargetDocument.Name.rstrip(App.TargetDocument.Title)
filename = path + "INTERNET_" + App.TargetDocument.Title
Code: Select all
'FileName': u'C:\\users\\Username\\Photos\\photoname.jpg',
Code: Select all
'FileName': filename,
Scripts by default are saved to scripts-restricted, this folder is for scripts that do simple things and don't need any permissions to your computer to run. Because you're saving a file you need to have it in scripts-trusted. These folders are usually in "C:\\users\\Username\\Documents\\Corel PaintShop Pro\\2018\\Scripts-Restricted" and "C:\\users\\Username\\Documents\\Corel PaintShop Pro\\2018\\Scripts-Trusted"
Here is a video demonstrating the process, I don't normally do this as they tend to be very long videos:
https://drive.google.com/file/d/1w4HOZW ... Ft1s6/view
https://levifiction.wordpress.com/
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Re: Save as procedure
Hello,
Thanks for your prompt reply.
I tried your suggestion and somehow I can not find the
"Code: Select all
def Do(Environment)"
I am presently using the 2018 version of the program and things might have changed.
In my previous version of the program, I remember someone suggesting to enter a couple of line which I think to remember they are similar to your:
filename=path+INTERNET_"+App.TargetDocument.Title
I do remember the + signs, but do not remember anything else about the command itself.
I also remember that the new file was saved in the same directory where the picture came from which usually was the directory open at the time.
I have taken the liberty of including the whole script here, hopefully you might be able to direct me where to make those changes.
I thank you for your interest in helping me.
Bert.
Here is the script:
from PSPApp import *
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'20.00'
}
def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# Resize
App.Do( Environment, 'Resize', {
'AspectRatio': 0.8,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': 504,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': True,
'Resolution': 72,
'Width': 403,
'SharpnessValue': 50,
'AdvancedMode': True,
'ResizeType': 2,
'OneSide_Type': 0,
'OneSide_LongWidth': 3780,
'OneSide_ShortHeight': 3024,
'OneSide_Unit': App.Constants.UnitsOfMeasure.Pixels,
'OneSide_Active': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'JPG': {
'Variant': App.Constants.JpegFormat.Standard,
'CompressionFactor': 20,
'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1,
'EXIF': True,
'EmbedJPGICC': True
}
},
'FileName': u'E:\\PICTURE STORAGE\\INTERNET-Amanda and Alyssa July 2017.JPG',
'FileFormat': App.Constants.FileFormat.JPG,
'FormatDesc': u'JPG JPEG ',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((20,0,0),1)
},
'DefaultProperties': []
})
# FileClose
App.Do( Environment, 'FileClose', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': -1,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
Thanks for your prompt reply.
I tried your suggestion and somehow I can not find the
"Code: Select all
def Do(Environment)"
I am presently using the 2018 version of the program and things might have changed.
In my previous version of the program, I remember someone suggesting to enter a couple of line which I think to remember they are similar to your:
filename=path+INTERNET_"+App.TargetDocument.Title
I do remember the + signs, but do not remember anything else about the command itself.
I also remember that the new file was saved in the same directory where the picture came from which usually was the directory open at the time.
I have taken the liberty of including the whole script here, hopefully you might be able to direct me where to make those changes.
I thank you for your interest in helping me.
Bert.
Here is the script:
from PSPApp import *
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'20.00'
}
def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# Resize
App.Do( Environment, 'Resize', {
'AspectRatio': 0.8,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': 504,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': True,
'Resolution': 72,
'Width': 403,
'SharpnessValue': 50,
'AdvancedMode': True,
'ResizeType': 2,
'OneSide_Type': 0,
'OneSide_LongWidth': 3780,
'OneSide_ShortHeight': 3024,
'OneSide_Unit': App.Constants.UnitsOfMeasure.Pixels,
'OneSide_Active': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'JPG': {
'Variant': App.Constants.JpegFormat.Standard,
'CompressionFactor': 20,
'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1,
'EXIF': True,
'EmbedJPGICC': True
}
},
'FileName': u'E:\\PICTURE STORAGE\\INTERNET-Amanda and Alyssa July 2017.JPG',
'FileFormat': App.Constants.FileFormat.JPG,
'FormatDesc': u'JPG JPEG ',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((20,0,0),1)
},
'DefaultProperties': []
})
# FileClose
App.Do( Environment, 'FileClose', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': -1,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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 procedure
You don't want "SELECT ALL" that's just something the forum puts in to let you select all of the code in the code snippet. You're only looking for "def Do(Environment):" and it's right there in the code you posted.
Also, the video I recorded was made in PSP2018. Nothing substantial has changed in scripting since PSP 8 so I know for a fact that this does work.
def Do(Environment): is the 12th line in your code.
You can use the FInd function inside of Notepad as well to search for text.
Here is your exact script with the three small changes I described. To make them easier to identify I've placed long bars of "#" symbols around my changes.
Also, the video I recorded was made in PSP2018. Nothing substantial has changed in scripting since PSP 8 so I know for a fact that this does work.
def Do(Environment): is the 12th line in your code.
You can use the FInd function inside of Notepad as well to search for text.
Here is your exact script with the three small changes I described. To make them easier to identify I've placed long bars of "#" symbols around my changes.
Code: Select all
from PSPApp import *
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'20.00'
}
def Do(Environment):
######################################################################
path = App.TargetDocument.Name.rstrip(App.TargetDocument.Title)
filename = path + "INTERNET_" + App.TargetDocument.Title
######################################################################
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# Resize
App.Do( Environment, 'Resize', {
'AspectRatio': 0.8,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': 504,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': True,
'Resolution': 72,
'Width': 403,
'SharpnessValue': 50,
'AdvancedMode': True,
'ResizeType': 2,
'OneSide_Type': 0,
'OneSide_LongWidth': 3780,
'OneSide_ShortHeight': 3024,
'OneSide_Unit': App.Constants.UnitsOfMeasure.Pixels,
'OneSide_Active': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'JPG': {
'Variant': App.Constants.JpegFormat.Standard,
'CompressionFactor': 20,
'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1,
'EXIF': True,
'EmbedJPGICC': True
}
},
##############################################################################
'FileName': filename,
##############################################################################
'FileFormat': App.Constants.FileFormat.JPG,
'FormatDesc': u'JPG JPEG ',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Interactive,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((20,0,0),1)
},
'DefaultProperties': []
})
# FileClose
App.Do( Environment, 'FileClose', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': -1,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
https://levifiction.wordpress.com/
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Re: Save as procedure
SUCCESS !!
Yes! it works perfectly.
Your written info and the video, help me a lot.
Everything is working as it should.
Thanks a lot for your continued interest in helping me.
Be well,
Bert
Yes! it works perfectly.
Your written info and the video, help me a lot.
Everything is working as it should.
Thanks a lot for your continued interest in helping me.
Be well,
Bert
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Re: Save as procedure
POSSIBLE REFINEMENT
Although as above mentioned, everything works fine.... I would like to try a possible refinement.
Is it possible to keep the aspect ratio of an image intact, while the script reduces its size?
At the present time the script indicates "Maintain Aspect Ratio: True"
But there are digits next to both, the Height and Width, which often gives a strange looking shape to the image after the script runs.
Is there a way to keep the Maintain Aspect Ratio: True, but only enter one size, either Height or Width and let the Aspect Ratio of the image be kept by the script?
Bert
Although as above mentioned, everything works fine.... I would like to try a possible refinement.
Is it possible to keep the aspect ratio of an image intact, while the script reduces its size?
At the present time the script indicates "Maintain Aspect Ratio: True"
But there are digits next to both, the Height and Width, which often gives a strange looking shape to the image after the script runs.
Is there a way to keep the Maintain Aspect Ratio: True, but only enter one size, either Height or Width and let the Aspect Ratio of the image be kept by the script?
Bert
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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 procedure
Yes, the easiest way is to re-record your script using the "Based on one side" option of the resize dialog. This will work all the way back to X7 if you're aiming for backwards compatibility.
In the Resize dialog click on the "Based on one side" radio button. You then have the choice of "Long side or Short side" or "Width or Height." Long side or short side lets you define the maximum size of the the shortest or the longest side. Handy when you know you need a maximum size or a minimum size of a side but you never know the orientation of the image.
By Width or Height you know which side specifically you always want to be a specific size.
Once you've chosen the type and side, enter in the value you wish to resize to. And Hit OK. Now re-edit your script with those three small changes previously discussed, the image should resize appropriately.
In previous versions of PSP (pre-X7) we had to manually calculate the aspect ratio (very easy) and enter that into the aspect ratio parameter, then calculate the new Width and Height and enter those in as well. It's super basic math but why bother when PSP will do the work for you?
In the Resize dialog click on the "Based on one side" radio button. You then have the choice of "Long side or Short side" or "Width or Height." Long side or short side lets you define the maximum size of the the shortest or the longest side. Handy when you know you need a maximum size or a minimum size of a side but you never know the orientation of the image.
By Width or Height you know which side specifically you always want to be a specific size.
Once you've chosen the type and side, enter in the value you wish to resize to. And Hit OK. Now re-edit your script with those three small changes previously discussed, the image should resize appropriately.
In previous versions of PSP (pre-X7) we had to manually calculate the aspect ratio (very easy) and enter that into the aspect ratio parameter, then calculate the new Width and Height and enter those in as well. It's super basic math but why bother when PSP will do the work for you?
https://levifiction.wordpress.com/
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Re: Save as procedure
Absolutely amazing. It works like a charm!
Thanks!
Is there a book with all the Script commands, so if I would like to do minor variations to the present script, I could find the steps, without bothering you?
Many many moons ago, prior to Corel buying it, WordPerfect, a word processor, had a thick book with all the macro commands. It was great and it help me a lot to write decision making macros which worked inside WordPerfect.
Does PaintShop Pro has a book like that?
Again I would like to refine the present script and be able to do all the images located in a directory and dumped the INTERNET copy files in a different directory.
Be well, and thanks a lot for your great help.
Bert
Thanks!
Is there a book with all the Script commands, so if I would like to do minor variations to the present script, I could find the steps, without bothering you?
Many many moons ago, prior to Corel buying it, WordPerfect, a word processor, had a thick book with all the macro commands. It was great and it help me a lot to write decision making macros which worked inside WordPerfect.
Does PaintShop Pro has a book like that?
Again I would like to refine the present script and be able to do all the images located in a directory and dumped the INTERNET copy files in a different directory.
Be well, and thanks a lot for your great help.
Bert
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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 procedure
You want batch Processing not scripting then. With batch processing you can select all of the images you want. Then add the resize command using the parameters that you want, then add a renaming scheme for saving. No need to do it all yourself.
Batch Processing works better than scripting in this instance because all you're doing is resizing. You can of course also run a script in a batch process so almost any time you want to perform actions on an entire folder you want to use batch processing not a custom script with saveas at the end of it.
To answer your question: Yes Corel does provide API documentation as well as a "Script for Script Authors" PDF that introduces you to scripting inside of PSP and things you need to be aware of. I would recommend learning the basics of Python before getting into that, though.
Links to the latest API (for version X8 but very little has changed from X8 to 2018 as far as scripting is concerned) as well as the scripting for script authors pdf and resources for learning Python can all be found in the first topic of this forum "Scripting Resources"
Here is a link to that topic: http://forum.corel.com/EN/viewtopic.php?f=104&t=56846
It starts off with Scripting for Script authors. THen the scripting API links, and then learning python resources.
I also recommend checking out Suz's Place, not that long ago her website was the premier place to go for coding snippets, including how to process an entire folder from a script without using Batch Process. Again for your needs Batch Process is more than sufficient.
Batch Processing works better than scripting in this instance because all you're doing is resizing. You can of course also run a script in a batch process so almost any time you want to perform actions on an entire folder you want to use batch processing not a custom script with saveas at the end of it.
To answer your question: Yes Corel does provide API documentation as well as a "Script for Script Authors" PDF that introduces you to scripting inside of PSP and things you need to be aware of. I would recommend learning the basics of Python before getting into that, though.
Links to the latest API (for version X8 but very little has changed from X8 to 2018 as far as scripting is concerned) as well as the scripting for script authors pdf and resources for learning Python can all be found in the first topic of this forum "Scripting Resources"
Here is a link to that topic: http://forum.corel.com/EN/viewtopic.php?f=104&t=56846
It starts off with Scripting for Script authors. THen the scripting API links, and then learning python resources.
I also recommend checking out Suz's Place, not that long ago her website was the premier place to go for coding snippets, including how to process an entire folder from a script without using Batch Process. Again for your needs Batch Process is more than sufficient.
https://levifiction.wordpress.com/
-
delgadob222
- Posts: 9
- Joined: Fri Dec 01, 2017 1:46 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
Re: Save as procedure
Magic, again!
Batch processing is absolutely amazing!
You guys are also absolutely AMAZING!
Thanks for the info.... and the lessons.
Bert
Batch processing is absolutely amazing!
You guys are also absolutely AMAZING!
Thanks for the info.... and the lessons.
Bert
-
rabsp9
- Posts: 1
- Joined: Sun Jan 14, 2018 6:59 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
- ram: 8gb
- Hard_Drive_Capacity: 20Tb
- Corel programs: Paintshop Pro, Aftershot Pro,
Re: Save as procedure
Thanks for this post, helped me out of my bind.
-
MikeFromMesa
- Posts: 269
- Joined: Mon Aug 08, 2011 4:13 pm
- System_Drive: N/A
- 32bit or 64bit: 64 Bit
- processor: 3.0 GHz Intel Core i7
- ram: 16 GB
- Video Card: Intel Iris
- Hard_Drive_Capacity: 256 GB SSD
- Monitor/Display Make & Model: 24" Dell Ultrasharp Monitor
- Corel programs: PaintShop Pro, AfterShot Pro
- Location: Mesa, AZ USA
Re: Save as procedure
I apologize for being so late to the conversation, but I have only spent a week or two using python so I was a bit late in reading the posts.LeviFiction wrote:I would recommend using the built-in variables App.TargetDocument.Name and App.TargetDocument.Title. Name is the full path of the file. Title is the filename. You can use the os library on Name to split the various parts of the filename apart or you can use the very simple rstrip and split functions.
I just wanted to mention that the App.TargetDocument variable Name is blank if you are loading a raw image and using Camera Raw Lab, although it is populated if opening a non-raw image or if opening a raw image, but not using CRL. This has caused me a bit of trouble in doing scripting since I generally use raw images and it is not possible (in any way I have been able to determine *) to find the original path when doing a normal Open command if you are loading a raw image and using CRL. If you discard CRL, then the problem disappears.
This means that all of my new scripts have to use a temporary file location and rely on the user to place the saved image in the proper folder.
* If there is some way to do this using raw images and CRL I would like to know what it is. It would save me perhaps 50 lines of code in my script.
Re: Save as procedure
I know this is a year old thread but I thought I found the answer I was looking for. I'm wanting to do basically the same thing as the OP. I copied the bits you added into my script but it won't load. I decided to copy and run the following script as a test. Well, I get an error that says the script could not be loaded. I'm using PSP2018. What might be the problem?
LeviFiction wrote: Here is your exact script with the three small changes I described. To make them easier to identify I've placed long bars of "#" symbols around my changes.
Code: Select all
from PSPApp import * def ScriptProperties(): return { 'Author': u'', 'Copyright': u'', 'Description': u'', 'Host': u'PaintShop Pro', 'Host Version': u'20.00' } def Do(Environment): ###################################################################### path = App.TargetDocument.Name.rstrip(App.TargetDocument.Title) filename = path + "INTERNET_" + App.TargetDocument.Title ###################################################################### # EnableOptimizedScriptUndo App.Do( Environment, 'EnableOptimizedScriptUndo', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match, 'Version': ((20,0,0),1) } }) # Resize App.Do( Environment, 'Resize', { 'AspectRatio': 0.8, 'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 'Height': 504, 'MaintainAspectRatio': True, 'Resample': True, 'ResampleType': App.Constants.ResampleType.Bicubic, 'ResizeAllLayers': True, 'Resolution': 72, 'Width': 403, 'SharpnessValue': 50, 'AdvancedMode': True, 'ResizeType': 2, 'OneSide_Type': 0, 'OneSide_LongWidth': 3780, 'OneSide_ShortHeight': 3024, 'OneSide_Unit': App.Constants.UnitsOfMeasure.Pixels, 'OneSide_Active': 0, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match, 'Version': ((20,0,0),1) } }) # FileSaveAs App.Do( Environment, 'FileSaveAs', { 'Encoding': { 'JPG': { 'Variant': App.Constants.JpegFormat.Standard, 'CompressionFactor': 20, 'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1, 'EXIF': True, 'EmbedJPGICC': True } }, ############################################################################## 'FileName': filename, ############################################################################## 'FileFormat': App.Constants.FileFormat.JPG, 'FormatDesc': u'JPG JPEG ', 'WorkingMode': 0, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Interactive, 'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 'Version': ((20,0,0),1) }, 'DefaultProperties': [] }) # FileClose App.Do( Environment, 'FileClose', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match, 'Version': ((20,0,0),1) } }) # SelectDocument App.Do( Environment, 'SelectDocument', { 'SelectedImage': -1, 'Strict': False, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match, 'Version': ((20,0,0),1) } })
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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 procedure
Can you copy the exact error you get? If you open the Script Output palette you should see a red/maroon text that shows exactly where the error is in trying to load the image.
https://levifiction.wordpress.com/
