from JascApp import * def ScriptProperties(): return { 'Author': u'SuzShook', 'Copyright': u'Copyright 2003 Suzshook', 'Description': u'Crops image and saves as PspTube tube', 'Host': u'Paint Shop Pro', 'Host Version': u'8.10' } def Do(Environment): try: # EnableOptimizedScriptUndo App.Do( Environment, 'EnableOptimizedScriptUndo', { }) except: None ### ### This code will extract the actual image name from the full path ### name returned from the FileName key in the ReturnImagaeInfo ### dictionary. It returns the image name with no path and no extension ### This code allows Export Tube to be run silently - version 01 ### # ReturnImageInfo ImageInfo = App.Do( Environment, 'ReturnImageInfo',) ImageName = ImageInfo['FileName'] LayerNum = ImageInfo['LayerNum'] Length = len(ImageName) ### ### This script will only work with previously saved images ### It uses the file name to generate the tube name ### if Length == 0: result = App.Do(Environment, 'MsgBox', { 'Buttons': App.Constants.MsgButtons.OK, 'Icon': App.Constants.MsgIcons.Stop, 'Text': "This script will only 'tube' a previously saved image.\nUse File...Export...Picture Tube for an unsaved image.\nScript will now stop.", }) print print " This script will only 'tube' a previously saved image." print " Use File...Export...Picture Tube for an unsaved image." print " Script will now stop." print return ### ### Images with more than 1 layer cannot be saved as picture tubes ### if LayerNum > 1: result = App.Do(Environment, 'MsgBox', { 'Buttons': App.Constants.MsgButtons.OK, 'Icon': App.Constants.MsgIcons.Stop, 'Text': 'This image has more than one layer.\nIt cannot be saved as a picture tube.\nScript will now stop.', }) print print " This image has more than one layer." print " It cannot be saved as a picture tube." print " Script will now stop." print return # ReturnLayerProperties LayerProps = App.Do( Environment, 'ReturnLayerProperties',) ### ### Flattened images cannot be saved as picture tubes ### if LayerProps['IsBackground'] == 1: result = App.Do(Environment, 'MsgBox', { 'Buttons': App.Constants.MsgButtons.OK, 'Icon': App.Constants.MsgIcons.Stop, 'Text': 'This image has a Background layer, and no transparency.\nIt cannot be saved as a picture tube.\nScript will now stop.', }) print print " This image has a Background layer, and no transparency." print " It cannot be saved as a picture tube." print " Script will now stop." print return count = 0 ### ### rfind finds highest index in string for character '\' ### count = ImageName.rfind('\\') #gives highest index in string for '\' Beginning = count + 1 End = 0 while (count < Length): # print "Image name at index ",count," is: ",ImageName[count] if ImageName[count] == '.': End = count count = Length else: count = count + 1 Name = ImageName[Beginning:End] TubeName = Name+'.PspTube' # SelectAll App.Do( Environment, 'SelectAll', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } }) # FloatSelection App.Do( Environment, 'FloatSelection', { 'ClearSource': None, 'BackupSelection': None, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } }) # DefloatSelection App.Do( Environment, 'DefloatSelection', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } }) # Crop App.Do( Environment, 'Crop', { 'Mode': App.Constants.CropMode.OpaqueLayer, 'Units': App.Constants.CropUnits.Pixels, 'SelectedArea': App.Constants.Boolean.true, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } }) # ExportTube App.Do( Environment, 'ExportTube', { 'FileName': TubeName, 'NumberOfCellsAcross': 1, 'NumberOfCellsDown': 1, 'TotalNumberOfCells': 1, 'PlacementMode': App.Constants.TubePlacementMode.Random, 'SelectionMode': App.Constants.TubeSelectionMode.Random, 'StepSize': 200, 'OverwriteIfExists': App.Constants.Boolean.true, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } })