Yes this is python scripting, it's not just the same they are literally using python. Because this is python using whitespace to indent lines under the for loop declaration statement will make the code block.
If your goal is to move a layer off screen and save a copy of the image after each small movement you want to put the for...loop before the Pick command, and then indent the Pick and FileSaveAs by an additional 4 spaces. Each line. I like using a full editor (like VS Code or Notepad++) for this as I just need to highlight it and then hit "tab" and it indents the line for me.
I recommend using the Move tool (command Name "Mover") as it only uses an offset parameter (x,y) so you don't have to do any math. Just set the offset to (10,0) and it'll move 10px to the right, set it to (-10,0) and it'll move 10px to the left every time it gets run. With the Pick tool, you have to move all 4 handles otherwise you'll end up stretching the layer. Not that this is hard, you're just subtracting 10 from the X value in each x,y pair. But you also want to calculate the new pivot point every time otherwise the pivot point will get left behind. And you have to get the current layer rectangle so that it can work on images of all sizes. It's just way easier to use Mover.
Code: Select all
# Move
App.Do( Environment, 'Mover', {
'Offset': (-10,0),
'Object': App.Constants.LayerOrSelection.Layer,
})
As for the filename. You can either use a library like os to do the work for you. Or you can use string manipulation. But essentially what you're wanting to do is separate the filename from the extension. I use the library method using the os library. Quick hint, App.TargetDocument is a variable that holds the image that was active when you started the script. And the member variable "Name" contains the full file pathname. If the image is brand new and hasn't been saved yet there will only be a name like "Image1" and no path.
Code: Select all
from PSPApp import *
import os
# ... code up to this point
filename, ext = os.path.spllitext(App.TargetDocument.Name)
Now we have two variables, the full filepath minus the extension and the extension. Since we'll be forcing this to save as PNG we'll want to use .'png' as the extension so we'll ignore the extension variable. There is another command inside the os.path library called "isfile" which will check the path and return true or false if the path leads to an existing file or not. I use this to determine if the Image is already saved or brand new. If it's brand new I save it to a default location.
Code: Select all
from PSPApp import *
import Os
#... code up to this point
if os.path.isfile(App.TargetDocument.Name):
filename, ext = os.path.splitext(App.TargetDocument.Name)
else:
filename = "c:\\Users\\Windows\\Downloads\\psp move left\\Image"
ext = '.png'
We then replace the "FileName" parameter with our new filename + str(x) + ext
Code: Select all
'FileName': filename + str(x) + ext,
And I'm going to make one final edit. I'm going to change the ExecutionMode of FileSaveAs to "Silent" so that it never asks for the filename even if you have "interactive" mode turned on. This is just my personal preference. You can leave this as "Default" if you want.
Now that the filename variable has been set up and I have moved from the Pick tool to the move tool this is all a lot easier.
Put the Move tool and FileSaveAs indented under the for loop and it'll loop 50 times to move the layer to the left by 500 pixels saving after each move. Here's the full code.
Code: Select all
for x in range(50):
# Move
App.Do( Environment, 'Mover', {
'Offset': (-10,0),
'Object': App.Constants.LayerOrSelection.Layer,
})
# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'PNG': {
'Interlaced': False,
'OptimizedPalette': True,
'AlphaChannel': False
}
},
'FileName': filename + str(x) + ext,
'FileFormat': App.Constants.FileFormat.PNG,
'FormatDesc': u'PNG Portable Network Graphics',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((22,0,0),1)
},
'DefaultProperties': []
})
If you want to move the layer completely off the canvas, it'll only work if the image is 500px right now. So you might want to make the number of loops equal to the Width of the image/10. Luckily App.TargetDocument also has a member variable named "Width" for the image width.
Code: Select all
loops = App.TargetDocument.Width /10
#Check if there is a remainder, if there is, add one more loop to finish it off
if App.TargetDocument.Width % 10 > 0:
loops += 1
Here's the entire script
Code: Select all
from PSPApp import *
import os
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'22.00'
}
def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((22,0,0),1)
}
})
loops = App.TargetDocument.Width /10
#Check if there is a remainder, if there is, add one more loop to finish it off
if App.TargetDocument.Width % 10 > 0:
loops += 1
if os.path.isfile(App.TargetDocument.Name):
filename, ext = os.path.splitext(App.TargetDocument.Name)
else:
filename = "c:\\Users\\Windows\\Downloads\\psp move left\\Image"
ext = ".png"
for x in range(loops):
# Move
App.Do( Environment, 'Mover', {
'Offset': (-10,0),
'Object': App.Constants.LayerOrSelection.Layer,
})
# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'PNG': {
'Interlaced': False,
'OptimizedPalette': True,
'AlphaChannel': False
}
},
'FileName': filename + str(x) + ext,
'FileFormat': App.Constants.FileFormat.PNG,
'FormatDesc': u'PNG Portable Network Graphics',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((22,0,0),1)
},
'DefaultProperties': []
})