Hi there,
I have PSPX2 and have entered a script for making sig tags. I've checked over the scripting step several time and have everything exactly as the tutorial shows. When I click on the play script button, I get the "working" curser and then see "not responding" at the top. That's as far as I get then have to close and restart PSP.
I make tons of sig tags for people so it would really help me to be able to get this to work.
Any ideas???
Thanks,
Erica
Make Tags Script in PSPX2
Moderator: Kathy_9
-
allicorn
- Posts: 135
- Joined: Sun Mar 16, 2008 12:39 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
- processor: Phenom II X6 1055T 3.2Ghz
- ram: 4Gb
- Video Card: ATI5670 1Gb + ATI4290 512Mb
- sound_card: Realtek HD onboard
- Hard_Drive_Capacity: 2Tb
- Monitor/Display Make & Model: Belinea B2025S1W + LG M197WDP
- Location: Somerset, UK
- Contact:
-
ericascott76
- Posts: 3
- Joined: Sat Jun 21, 2008 4:07 pm
re:
I don't think so. This is my first time at scripting so I'm completely new (not to PSP, but to scripts) 
-
allicorn
- Posts: 135
- Joined: Sun Mar 16, 2008 12:39 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
- processor: Phenom II X6 1055T 3.2Ghz
- ram: 4Gb
- Video Card: ATI5670 1Gb + ATI4290 512Mb
- sound_card: Realtek HD onboard
- Hard_Drive_Capacity: 2Tb
- Monitor/Display Make & Model: Belinea B2025S1W + LG M197WDP
- Location: Somerset, UK
- Contact:
-
ericascott76
- Posts: 3
- Joined: Sat Jun 21, 2008 4:07 pm
Code: Select all
from JascApp import *
def ScriptProperties():
return {
'Author': u'Julie Stenning',
'Copyright': u'Julie Stenning',
'Description': u'',
'Host': u'Paint Shop Pro',
'Host Version': u'8.10'
}
# This script can not easily be run without instructions.
# If you receive this script without instructions then please retrieve full package from
# http://jstenning.me.uk/Scripts/TJP-Scripts.htm. There is a version on the web site for
# PSP 9.
# I have a yahoo support group http://groups.yahoo.com/group/TJPMakeTagsScript that you
# may be interested in joining. If you work with the script successfully then you may like to
# help in the support group. If you are having issues then you may get a response from the group
# more quickly than a response from me. My e-mail address is julie@stenning.org.uk
# The script WILL NOT WORK with PSP 8.00. Free updates are available on the PSP web site.
'''
License Information
This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
'''
##################################################################################
# Go to the bottom of the file to view the version history of the tag maker
##################################################################################
##################################################################################
# Set global variables.
##################################################################################
# ---------------------------------------------------------------------------
# Files which the script uses
# ---------------------------------------------------------------------------
# The name of the file with the list of names. Full path should be included.
# Put the file name inside the quotes. Leave the r there. E.G. r"E:\Names.txt"
# This is required.
strListofNamesFile = r"C:\Users\Erica\Desktop\test.txt"
# The name of the file which the tag is based on. Full path should be included.
# Put the file name inside the quotes. Leave the r there. E.G. r"E:\TagTemplate.PspImage".
# This is optional. If you don't fill this in then you need to have the template file open in PSP
# when you run the script.
strTemplateFileName = r""
# The name of the script which is used to write the text on your tags. Should not include a path or
# the .PspScript file extension.
# This is required.
str1stTextAddingScript = "blank1test"
# The name of the script which is used to write the 2 lines of text on your tags when they are too long
# to fit on one line. Should not include a path or the .PspScript file extension.
# This is optional.
str2ndTextAddingScript = ""
# The name of the script which is used to format the text on your tags. Should not include a path or
# the .PspScript file extension.
# This is optional.
strFormattingScriptFile = "blank1testa"
# ---------------------------------------------------------------------------
# Variables to do with saving the tags.
# ---------------------------------------------------------------------------
# The full path to the directory that the tags will be saved in without the final back slash
# Put the directory name inside the quotes. Leave the r there. E.G. r"e:\tags"
strSaveDir = r"C:\Users\Erica\Desktop\Scripts"
# The text which should be added to the front of the file name for any tag made.
# This is optional.
strFilePrefix = ""
# The text which should be added to the end of the file name for any tag made.
# This is optional.
strFileSuffix = ""
# The file format: 1 for JPG, 2 for PSP 8, 3 for PSP 7 (Animation Shop) and 4 for GIF
intFileSaveType = 1
# JPG compression to be used when saving JPG files. It is required if the file format is 1 for jpg.
intJPGCompression = 10
# ---------------------------------------------------------------------------
# Variables to do with controlling the text
# ---------------------------------------------------------------------------
# MC if the font is mixed case, LC is it is lower case and UC if it is upper case.
# This is required.
strFontType = "MC"
# Y if the font copes with accents otherwise N.
# This is required.
strFontHasAccents = "Y"
# The number of pixels to be reserved on each side of the tag for a border.
# This is required.
intBorder = 10
# The direction of the tag name, H for Horizonal and V for Vertical. The tag making script assumes
# that if the tag name is Horizontal, it will only have to fit large names across the horizontal and not the
# vertical. If the tag name is Vertical, the script will only have to fit large names up and down the tag and
# not widthways.
# This is required.
strTagNameDirection = "H"
# If you are using text on a path to add your tag names then the script will not automatically
# centre tag names which are too long to fit on the template.
# This is required and the possible values are N or Y
strTextOnAPath = "N"
# If a tag name is too long to fit on the image and it is not text on a path, then the tag maker
# will resize the tag to fit. Unfortunately, the resizing re-positions the text so it has to be
# moved back to the right place. This next variable is for you to tell the tag maker if it should
# move the text so the left side of the text is where it was before resizing, or the right side of the
# text is where it was before resizing or if it should be moved so the centre positions match.
# This is required and the possible values are L for Left, R for Right and C for Centre
strVerticalTextReposition = "R"
# If your tag names are created by writing text on a path then if the tag name cannot be fitted on
# to the image, then the script will stop and tell you if this is set to Y.
# If it is set to N then the script will carry on and give you a list of names
# which could not be done when all other tags have been made.
# This is required and the possible values are N or Y
strStopIfTooLarge = "N"
# ---------------------------------------------------------------------------
# Miscellaneous variables
# ---------------------------------------------------------------------------
# Set to Y if you want to see debug messages in the SOP
strDebug = "N"
##########
# Don't touch anything below here
# #############
# #############
# Main Script
# #############
#############
# Non-User Defined Global variables
#
# Initialise list of failed tags
listNotDoneNames = []
def Do(Environment):
import JascUtils
import time
local = time.localtime (time.time())
starttime = time.strftime ('%c' ,(local))
print "Start time: ",starttime
print "Running version 1.11 of the Make Tags Script"
# FileOpen
App.Do( Environment, 'FileOpen', {
'FileList': [strTemplateFileName],
'FileFormat': App.Constants.FileFormat.Unknown,
'ShowPreview': App.Constants.Boolean.false,
'EnableBrowser': App.Constants.Boolean.true,
'FavFileList': [],
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': 0,
'Strict': App.Constants.Boolean.false,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# The script relies on an open template document.
# Check to see that there is a document. If there isn't then raise an error
try:
Width = App.ActiveDocument.Width
except:
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must have an open image to create the tags from. Script will be aborted.",
})
return
PrintUserSelections()
if CheckUserSelections(Environment) == "N":
return
intImageWidth = App.ActiveDocument.Width
intImageHeight = App.ActiveDocument.Height
# GetVersionInfo
Version = App.Do(Environment, 'GetVersionInfo')
print "The version of psp is " + Version['VersionString']
intMajorVersion = Version['MajorVersion']
#######################################
# Process the names
try:
intNoTagsCreated = 0
# Try to open the list of names file and raise an error if it fails
try:
fileNameFile = open(strListofNamesFile)
except:
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The file of names does not exist or this script is not in your trusted folder.",
})
return
if intFileSaveType == 1:
strFileExtension = ".jpg"
elif intFileSaveType == 2:
strFileExtension = ".PspImage"
elif intFileSaveType == 3:
strFileExtension = ".psp"
elif intFileSaveType == 4:
strFileExtension = ".gif"
for strFileTagName in fileNameFile.readlines():
# Initialise variables for new tag name
strDone2ndTextAddingScript = "N"
strNameWasTooLong = "N"
strTagName = strFileTagName.strip()
# Replace characters which cannot be used as file names
strTagName = strTagName.replace("\\","")
strTagName = strTagName.replace("/","")
strTagName = strTagName.replace(":","")
strTagName = strTagName.replace("*","")
strTagName = strTagName.replace("?","")
strTagName = strTagName.replace("<","")
strTagName = strTagName.replace(">","")
strTagName = strTagName.replace('"',"")
if strFontType.upper() == "UC":
strTagName = strTagName.upper()
elif strFontType.upper() == "LC":
strTagName = strTagName.lower()
if len(strTagName) > 0:
print "Doing tag for: ", strTagName
if strFontHasAccents == "N":
strTagName = ReplaceAccents(strTagName)
# If the file is there already don't process it.
# Check the file extensions first.
# FontType LC for lower case, UC for upper case and MC for Mixed case
if strFontType.upper() == "MC":
if strTagName.islower():
strFileCaseSuffix = "-lc"
elif strTagName.isupper():
strFileCaseSuffix = "-UC"
elif strTagName.istitle():
strFileCaseSuffix = ""
else:
strFileCaseSuffix = "-MC"
else:
strFileCaseSuffix = ""
try:
strFileName = strSaveDir + '\\' + strFilePrefix + strTagName + strFileSuffix + strFileCaseSuffix + strFileExtension
fileNameFile = open(strFileName)
fileNameFile.close()
except:
# The file isn't there so carry on processing the tag
# DuplicateWindow
App.Do( Environment, 'DuplicateWindow', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': 0,
'Strict': App.Constants.Boolean.false,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Start by moving to the top layer
# SelectLayer
App.Do( Environment, 'SelectLayer', {
'Path': (0,999,[],App.Constants.Boolean.false),
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
### Create a new layer if this one is a raster layer, otherwise rename this vector layer
### to the tag name
### 0 is raster, 1 is vector
Results = App.Do(Environment, 'ReturnLayerProperties')
LayerType = Results['LayerType']
if LayerType == 0:
###
### Add vector layer for
### text with Name to be used for tag
###
# New Vector Layer
App.Do( Environment, 'NewVectorLayer', {
'General': {
'Opacity': 100,
'Name': strTagName,
'IsVisible': App.Constants.Boolean.true,
'IsTransparencyLocked': App.Constants.Boolean.false,
'LinkSet': 0,
'UseHighlight': App.Constants.Boolean.false,
'PaletteHighlightColor': (255,255,64),
'GroupLink': App.Constants.Boolean.true,
'BlendMode': App.Constants.BlendMode.Normal
},
'BlendRanges': {
'BlendRangeGreen': (0,0,255,255,0,0,255,255),
'BlendRangeRed': (0,0,255,255,0,0,255,255),
'BlendRangeBlue': (0,0,255,255,0,0,255,255),
'BlendRangeGrey': (0,0,255,255,0,0,255,255)
},
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
else:
# Layer Properties
App.Do( Environment, 'LayerProperties', {
'General': {
'Name': strTagName
},
})
FileTagName = strTagName
if strDebug == "Y" :
print "Running 1st script file " + str1stTextAddingScript
# call the 1st script file
# RunSelectedScript
App.Do( Environment, 'RunSelectedScript', {
'ScriptName': str1stTextAddingScript,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
if strDebug == "Y":
print "Completed the 1st script"
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
# Do this for width and height
################################
# DOING THE WIDTH
################################
# if the text sticks out over the image,
# if there are spaces and 2 scripts for text adding, then set the layers appropriately
# and run the second script
# if the text sticks out over the image
# if the text is straight then auto move (horiz for width and vert for height)
# else raise an error
strSticksOut = "N"
if x < 0:
intPositionCheckX = 0
strSticksOut = "Y"
else:
intPositionCheckX = x
if y < 0:
intPositionCheckY = 0
strSticksOut = "Y"
else:
intPositionCheckY = y
if y + dy > intImageHeight - intBorder:
strSticksOut = "Y"
# Does the text stick out wider or higher than the image?
if ((intPositionCheckX + dx > intImageWidth - (intBorder * 2) and strTagNameDirection == "H") or (intPositionCheckY + dy > intImageHeight - (intBorder*2) and strTagNameDirection=="V")) or strSticksOut == "Y":
if strDebug == "Y":
print "The text is wider than the image"
print "intPositionCheckX " , intPositionCheckX
print "dx " , dx
print "intImageWidth ", intImageWidth
print "intBorder * 2 ", intBorder * 2
print "intPositionCheckX + dx ", intPositionCheckX + dx
print "intImageWidth - (intBorder * 2) ", intImageWidth - (intBorder * 2)
# If there is a 2nd text adding script and there is a space in the tag name then
# run the second text adding script.
if str2ndTextAddingScript <> "" and FileTagName.replace(' ','') != FileTagName:
if strDebug =="Y":
print "Calling Run2ndScript"
Run2ndScript(Environment,FileTagName)
strDone2ndTextAddingScript = "Y"
else:
strDone2ndTextAddingScript = "N"
# Either there isn't a 2nd script to add text or there is no space in the tag name
if strDebug =="Y":
print "Either there isn't a 2nd script to add text or there is no space in the tag name"
if strTagNameDirection == "H":
if strDebug =="Y":
print "Calling SortOutWidth"
strNameWasTooLong = SortOutWidth(Environment,strDone2ndTextAddingScript,strStopIfTooLarge,strTagName,intMajorVersion)
if strTagNameDirection == "V":
if strDebug =="Y":
print "Calling SortOutHeight"
strNameWasTooLong = SortOutHeight(Environment,strDone2ndTextAddingScript,strStopIfTooLarge,strTagName,strVerticalTextReposition)
if strNameWasTooLong == "N":
if strFormattingScriptFile <> "":
# RunSelectedScript
App.Do( Environment, 'RunSelectedScript', {
'ScriptName': strFormattingScriptFile,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
SaveTheFile(Environment,FileTagName,strFileExtension, strFileCaseSuffix)
intNoTagsCreated = intNoTagsCreated + 1
else:
if strNameWasTooLong == "Y":
listNotDoneNames.append(strTagName)
if strDebug == "Y":
print "added " + strTagName + " to the list"
###
### Close Tag File
###
# FileClose
App.Do( Environment, 'FileClose', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# End Except:
# EndIf Checking that the tag name has length
#End Loop - File read complete
# Close the file of names because they are all done now
fileNameFile.close()
# Report on tags that could not be made
if len(listNotDoneNames) > 0:
print "****************************************"
print "The following tags could not be made because the names were too large to fit on the tags"
for i in range(0,len(listNotDoneNames)):
print listNotDoneNames[i]
print "****************************************"
except:
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "There was an error creating the tags.",
})
local = time.localtime (time.time())
endtime = time.strftime ('%c' ,(local))
print
print " Start time: ",starttime
print " End time: ",endtime
print
print " I just made " + str(intNoTagsCreated) + " tags."
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Info,
'Text': "Finished.",
})
def Run2ndScript(Environment,FileTagName):
if strDebug == "Y" :
print "There is a second script"
print "There is a space in the name"
# Working out where the tag name should be split. Trying to split it
# such that half is written by the first part of the 2nd text adding script
# and the other half is written by the second part.
# There will be a layer name of Firstpart*SecondPart which is then used
# by the second text adding script.
# Find out how many spaces there are
intTagNameLength = len(FileTagName)
intNumSpaces = FileTagName.count(' '[0:intTagNameLength])
if strDebug == "Y" :
print "intTagNameLength: " + str(intTagNameLength)
print "intNumSpaces: " + str(intNumSpaces)
# Find out the half point
intHalfPoint = (intTagNameLength / 2) - 1 # Indexes for counting start at 0 and comparing these counts to this figure
if strDebug == "Y" :
print "intHalfPoint: " + str(intHalfPoint)
intOldLocation = 0
intCurrentLocation = 0
intOldDistance = intTagNameLength
strStringCheck = FileTagName
for x in range(0,intTagNameLength - 1) :
strStringCheck = FileTagName[x:intTagNameLength]
if strStringCheck.startswith(' ') :
if strDebug == "Y" :
print "string check " + strStringCheck
print "got a space"
intCurrentLocation = intTagNameLength - len(strStringCheck)
if strDebug == "Y" :
print "intCurrentLocation " + str(intCurrentLocation)
if intCurrentLocation <= intHalfPoint :
intCurrentDistance = intHalfPoint - intCurrentLocation
if strDebug == "Y" :
print "on Left"
print "intCurrentDistance" + str(intCurrentDistance)
else :
intCurrentDistance = intCurrentLocation - intHalfPoint
if strDebug == "Y" :
print "on Right"
print "intCurrentDistance" + str(intCurrentDistance)
if intCurrentDistance < intOldDistance :
intOldLocation = intCurrentLocation
intOldDistance = intCurrentDistance
if strDebug == "Y" :
print "Changed the location " + str(intOldLocation)
strTagName1 = FileTagName[0:intOldLocation]
strTagName2 = FileTagName[intOldLocation + 1 : intTagNameLength]
strTagName1 = strTagName1.rstrip()
strTagName1 = strTagName1.lstrip()
strTagName2 = strTagName2.rstrip()
strTagName2 = strTagName2.lstrip()
if strDebug == "Y" :
print "Tag Name 1: " + strTagName1
print "Tag Name 2: " + strTagName2
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
# Clear the text already written which was too long and rename the vector layer
# ClearSelection
App.Do( Environment, 'ClearSelection', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Layer Properties
App.Do( Environment, 'LayerProperties', {
'General': {
'Name': strTagName1 + "*" + strTagName2
},
})
if strDebug == "Y" :
print "Running the 2nd text adding script file: " + str2ndTextAddingScript
# call the the 2nd text adding script file
# RunSelectedScript
App.Do( Environment, 'RunSelectedScript', {
'ScriptName': str2ndTextAddingScript,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
strDone2ndTextAddingScript = "Y"
def SortOutHeight(Environment,strDone2ndTextAddingScript,strStopIfTooLarge,strTagName,strVerticalTextReposition):
# If the 2nd script has been run then we need to ensure that we select both vector objects,
# not just the last one.
intImageHeight = App.ActiveDocument.Height
strSticksOut = "N"
strNameWasTooLong = "N"
if strDone2ndTextAddingScript == "Y" :
print ""
print "Don't worry if you see error messages here."
print ""
try:
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[3],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.Select,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[4],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.AddToSelection,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
except:
try:
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[1],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.Select,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[2],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.AddToSelection,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
except:
print ""
print ""
print "Start paying attention to error messages from here."
print ""
else:
if strDebug == "Y":
print "not selecting 2 objects."
# end checking to see if 2 objects should be selected
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
intLayerHeight = dy
if y < 0:
intPositionCheck = 0
strSticksOut = "Y"
else:
intPositionCheck = y
# Does the text stick out higher or lower than the image?
if (intPositionCheck + dy + (intBorder*2) > intImageHeight) or strSticksOut == "Y":
if strDebug == "Y":
print "The text is higher or lower than the image"
if strTextOnAPath == "Y":
if strStopIfTooLarge == "Y":
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The name " + strTagName + " sticks out. See SOP for the length. Script will be aborted",
})
print "The tag name is ", len(strTagName), " characters long"
fileNameFile.close()
else:
strNameWasTooLong = "Y"
# Auto Moving the text
else :
# If the text is above the image, move it to position 0 + the border size
# of the image width
if y < 0 or strSticksOut == "Y":
if strDebug == "Y" :
print "Text is above the image"
# VectorMove
App.Do( Environment, 'VectorMove', {
'MoveX': 0,
'MoveY': -y + (intImageHeight/100) + intBorder,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
if y + dy + (intBorder * 2) > intImageHeight:
# VectorAlignVCenterInCanvas
App.Do( Environment, 'VectorAlignVCenterInCanvas', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
if y + dy + (intBorder * 2) > intImageHeight:
# For some peculiar reason, resize the layer in PSP also moves it.
# Find out where the x position of the central part of the text is.
# When it has moved due to the resize, move it back again
intOriginalCentrex = x + (dx/2)
intOriginalRightx = x + dx
intOriginalLeftx = x
intPercentChange = ((intImageHeight - (intBorder * 2))/dy) * 100
if strDebug == "Y" :
print "Percent ",intPercentChange
if intPercentChange < 100:
# Resize
App.Do( Environment, 'Resize', {
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Percent,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': intPercentChange,
'MaintainAspectRatio': App.Constants.Boolean.true,
'Resample': App.Constants.Boolean.true,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': App.Constants.Boolean.false,
'Width': intPercentChange,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
intCurrentCentrex = x + (dx/2)
intCurrentRightx = x + dx
intCurrentLeftx = x
if strVerticalTextReposition == "C":
intAmountToMove = intOriginalCentrex - intCurrentCentrex
elif strVerticalTextReposition == "L":
intAmountToMove = intOriginalLeftx - intCurrentLeftx
elif strVerticalTextReposition == "R":
intAmountToMove = intOriginalRightx - intCurrentRightx
if strDebug == "Y":
print "strVerticalTextReposition " + strVerticalTextReposition
if strVerticalTextReposition == "C":
print "intOriginalCentrex ", intOriginalCentrex
print "intCurrentCentrex ", intCurrentCentrex
elif strVerticalTextReposition == "L":
print "intOriginalLeftx ", intOriginalLeftx
print "intCurrentLeftx ", intCurrentLeftx
elif strVerticalTextReposition == "R":
print "intOriginalRightx ", intOriginalRightx
print "intCurrentRightx ", intCurrentRightx
print "intAmountToMove ", intAmountToMove
# VectorMove
App.Do( Environment, 'VectorMove', {
'MoveX': intAmountToMove,
'MoveY': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# VectorAlignVCenterInCanvas
App.Do( Environment, 'VectorAlignVCenterInCanvas', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
if strDebug == "Y":
print "strNameWasTooLong ", strNameWasTooLong
return strNameWasTooLong
def SortOutWidth(Environment,strDone2ndTextAddingScript,strStopIfTooLarge,strTagName,intMajorVersion):
###################################
# DONE THIS BIT FOR WIDTH
# Do this for width and height
# if the text sticks out over the image,
# if there are spaces and 2 scripts for text adding, then set the layers appropriately
# and run the second script
###################################
# DOING THIS BIT FOR WIDTH
# if the text sticks out over the image
# if the text is straight then auto move (horiz for width and vert for height)
# else raise an error
###################################
# If the 2nd script has been run then we need to ensure that we select both vector objects,
# not just the last one.
intImageWidth = App.ActiveDocument.Width
intImageHeight = App.ActiveDocument.Height
strSticksOut = "N"
strNameWasTooLong = "N"
if strDone2ndTextAddingScript == "Y" :
print ""
print "Don't worry if you get an error message when doing this bit."
print ""
try:
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[3],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.Select,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[4],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.AddToSelection,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
except:
try:
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[1],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.Select,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
# VectorSelectionUpdate
App.Do( Environment, 'VectorSelectionUpdate', {
'Path': (9999,9999,[2],App.Constants.Boolean.false),
'Type': App.Constants.ObjectSelection.AddToSelection,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Default
}
})
except:
print ""
print ""
print "Error messges should be observed from here."
print ""
else:
if strDebug == "Y":
print "not selecting 2 objects."
# end checking to see if 2 objects should be selected
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
if x < 0:
intPositionCheck = 0
strSticksOut = "Y"
else:
intPositionCheck = x
# Does the text stick out wider than the image?
if (intPositionCheck + dx + (intBorder*2) > intImageWidth) or strSticksOut == "Y":
if strDebug == "Y":
print "The text is wider than the image"
if strTextOnAPath == "Y":
if strStopIfTooLarge == "Y":
# MsgBox
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The name " + strTagName + " sticks out. See SOP for the length. Script will be aborted",
})
print "The tag name is ", len(strTagName), " characters long"
fileNameFile.close()
else:
strNameWasTooLong = "Y"
# Auto Moving the text
else :
# If the text is to the left of the image, move it to position 0 + the border size
# of the image width
if x < 0 or strSticksOut == "Y":
if strDebug == "Y" :
print "Text is to the left of the image"
# VectorMove
App.Do( Environment, 'VectorMove', {
'MoveX': -x + (intImageWidth/100) + intBorder,
'MoveY': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
if x + dx + (intBorder * 2) > intImageWidth:
# VectorAlignHCenterInCanvas
App.Do( Environment, 'VectorAlignHCenterInCanvas', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
x = VRectangle [0][0]
y = VRectangle [0][1]
dx = VRectangle [1]
dy = VRectangle [2]
if x + dx + (intBorder * 2) > intImageWidth:
intPercentChange = ((intImageWidth - (intBorder * 2))/dx) * 100
if strDebug == "Y" :
print "Percent ",intPercentChange
if intPercentChange < 100:
# Don't ask me why, but resizing the layer moves the text up.
# Need to record where it is before doing the move and move it to the
# correct place afterwards.
intOriginalBottomy = y + dy
# Resize
App.Do( Environment, 'Resize', {
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Percent,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': intPercentChange,
'MaintainAspectRatio': App.Constants.Boolean.true,
'Resample': App.Constants.Boolean.true,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': App.Constants.Boolean.false,
'Width': intPercentChange,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# Get the text positions again since the text has moved
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
y = VRectangle [0][1]
dy = VRectangle [2]
intCurrentBottomy = y + dy
if intCurrentBottomy > intOriginalBottomy:
intAmountToMove = intCurrentBottomy - intOriginalBottomy
else:
intAmountToMove = intOriginalBottomy - intCurrentBottomy
if strDebug == "Y":
print "Original y position of bottom is ", intOriginalBottomy
print "Current y position of bottom is ", intCurrentBottomy
print "Going to move down ", intAmountToMove
# I don't understand why, but in PSP 9 and PSP 10, when I have 2 lines of text,
# there is a bigger gap between the two lines than in PSP 8.
# What is worse, the vector nudge move appears to be moving the text
# twice as far as it should, even when using keys. So, I'm dividing the amount
# to move by 2. It may be something to do with the way I wrote my 2nd text adding
# script. Hopefully testing will iron it out.
if (intMajorVersion == 9 or intMajorVersion == 10) and strDone2ndTextAddingScript == "Y":
intAmountToMove = intAmountToMove / 2
# VectorMove
App.Do( Environment, 'VectorMove', {
'MoveX': 0,
'MoveY': intAmountToMove,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# VectorAlignHCenterInCanvas
App.Do( Environment, 'VectorAlignHCenterInCanvas', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# If the text sticks out below the border or the image then move it so
# the bottom is just above the border
# Get Selection Info
VSelectionInfo = App.Do( Environment, 'GetVectorSelectionRect' )
VRectangle = VSelectionInfo['VectorRect']
y = VRectangle [0][1]
dy = VRectangle [2]
if y + dy > intImageHeight - intBorder:
intAmountToMove = (y + dy) - (intImageHeight - intBorder)
if strDebug == "Y":
print "Position of bottom of tag", y + dy
print "Position it should be at ", intImageHeight - intBorder
print "Amount to move ", (y + dy) - (intImageHeight - intBorder)
# VectorMove
App.Do( Environment, 'VectorMove', {
'MoveX': 0,
'MoveY': - intAmountToMove,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
if strDebug == "Y" and strNameWasTooLong <> "":
print "strNameWasTooLong ", strNameWasTooLong
return strNameWasTooLong
def PrintUserSelections():
print
print
print "List of Names File: " + strListofNamesFile
print
print "TeFt to add to the front of the file name: " + strFilePrefix
print
print "Text to add to the end of the file name: " + strFileSuffix
print
print "Text writing script name: " + str1stTextAddingScript
print
print "Text formatting script name: " + strFormattingScriptFile
print
if intFileSaveType == 1:
print "File Save Type is 1 - jpg format"
print
elif intFileSaveType == 2:
print "File Save Type is 2 - PSP 8 format"
print
elif intFileSaveType == 3:
print "File Save Type is 3 - PSP 7 (Animation Shop) format"
print
elif intFileSaveType == 4:
print "File Save Type is 4 - Gif format"
print
if intFileSaveType == 1:
print "JPG Compression: " + str(intJPGCompression)
print
if strFontType.upper() == "LC":
print "The font is a lower case font"
print
elif strFontType.upper() == "UC":
print "The font is a upper case font"
print
elif strFontType.upper() == "MC":
print "The font is a mixed case font"
print
print "Directory for saving tags: " + strSaveDir
print
print "2nd Text writing script name: " + str2ndTextAddingScript
print
print "Debugging? " + strDebug
print
print
def CheckUserSelections(Environment):
str1stTextAddingScriptUpper = str1stTextAddingScript.upper()
str2ndTextAddingScriptUpper = str2ndTextAddingScript.upper()
strFormattingScriptFileUpper = strFormattingScriptFile.upper()
strSaveDirUpper = strSaveDir.upper()
strSuccess = "Y"
# Check that the user has entered mandatory information
if strListofNamesFile == '':
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must have a file with a list of names for the tags. Script will be aborted",
})
strSuccess = "N"
elif str1stTextAddingScript == '':
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must state the name of the text entry script. Script will be aborted.",
})
strSuccess = "N"
elif len(str1stTextAddingScript) != len(str1stTextAddingScript.replace("\\","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for str1stTextAddingScript includes folder names. The setting here must not include a folder name or the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif len(str1stTextAddingScript) != len(str1stTextAddingScriptUpper.replace(".PSPSCRIPT","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for str1stTextAddingScript includes the .PspScript extension. The setting here must not include the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif len(str2ndTextAddingScript) != len(str2ndTextAddingScript.replace("\\","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for str2ndTextAddingScript includes folder names. The setting here must not include a folder name or the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif len(str2ndTextAddingScript) != len(str2ndTextAddingScriptUpper.replace(".PSPSCRIPT","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for str2ndTextAddingScript includes the .PspScript extension. The setting here must not include the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif len(strFormattingScriptFile) != len(strFormattingScriptFile.replace("\\","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for strFormattingScriptFile includes folder names. The setting here must not include a folder name or the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif len(strFormattingScriptFile) != len(strFormattingScriptFileUpper.replace(".PSPSCRIPT","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "The definition for strFormattingScriptFile includes the .PspScript extension. The setting here must not include the .PspScript extension. Script will be aborted.",
})
strSuccess = "N"
elif strSaveDir == '':
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must state the directory that your tags should be saved in. Script will be aborted.",
})
strSuccess = "N"
elif len(strSaveDir) != len(strSaveDirUpper.replace("\\U","")):
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "For technical reasons, a folder name starting with a 'U' or a 'u' cannot be used for saving the tags. Script will be aborted.",
})
strSuccess = "N"
elif intFileSaveType != 1 and intFileSaveType !=2 and intFileSaveType != 3 and intFileSaveType != 4:
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must set the file save type to a value of 1, 2, 3 or 4. Script will be aborted.",
})
strSuccess = "N"
elif intFileSaveType == 1 and intJPGCompression == '':
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must state jpg compression when saving jpgs. Script will be aborted.",
})
strSuccess = "N"
elif strFontType == '':
App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': "You must set strFontType to UC (upper case), LC (lower case) or MC (mixed case). Script will be aborted.",
})
strSuccess = "N"
elif str
Last edited by ericascott76 on Sat Jun 21, 2008 5:45 pm, edited 1 time in total.
-
allicorn
- Posts: 135
- Joined: Sun Mar 16, 2008 12:39 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
- processor: Phenom II X6 1055T 3.2Ghz
- ram: 4Gb
- Video Card: ATI5670 1Gb + ATI4290 512Mb
- sound_card: Realtek HD onboard
- Hard_Drive_Capacity: 2Tb
- Monitor/Display Make & Model: Belinea B2025S1W + LG M197WDP
- Location: Somerset, UK
- Contact:
Hoohoo - I think you'll have to use the "CODE" tags to get the forum to post it right. You can try editing the post and put [/code]
EDIT:
Mmm, thats just not working right is it? I think the forum had a bit of a fit
You can always attached it on an email if you like: allicorn(AT)gmail.com
Alli
Code: Select all
[code] the script EDIT:
Mmm, thats just not working right is it? I think the forum had a bit of a fit
You can always attached it on an email if you like: allicorn(AT)gmail.com
Alli
- Ron P.
- Advisor
- Posts: 12002
- Joined: Tue May 10, 2005 12:45 am
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Hewlett-Packard 2AF3 1.0
- processor: 3.40 gigahertz Intel Core i7-4770
- ram: 16GB
- Video Card: NVIDIA GeForce GTX 645
- sound_card: NVIDIA High Definition Audio
- Hard_Drive_Capacity: 4TB
- Monitor/Display Make & Model: 1-HP 27" IPS, 1-Sanyo 21" TV/Monitor
- Corel programs: VS5,8.9,10-X5,PSP9-X8,CDGS-9,X4,Painter
- Location: Kansas, USA
-
Tim Morrison
- Moderator
- Posts: 341
- Joined: Wed Mar 26, 2008 3:42 pm
- System_Drive: C
- 32bit or 64bit: 32 Bit
- motherboard: Asus P4533
- processor: 3.16 GHz
- ram: 2GB
- Video Card: Radeon HD4650
- Hard_Drive_Capacity: 2.6 TB
- Monitor/Display Make & Model: HP LP2275W
- Location: Australia
I'm certainly no scripting expert, but one thing that seems to be missing is the indenting of lines in the program listing. In many programming languages the indenting of lines of code is nothing but a convenience to make the listing easier to follow, but in Python it is an integral part of the program, and is used to identify loops and sub-routines.
