It creates a vector grid over an image.
JoeB suggested I post it here.
Joëlle ------ Hmm 'the extension pspscript is not allowed'. VERY handy in a scripting forum.
Edit: removed the text, will attach the zipped file, if that works...
Moderator: Kathy_9
Code: Select all
ImportError: No module named PSPUtilsThanks LeviFiction. Nearly there! It runs in PSP 8 without error and allows input at each stage - but no result is displayed. The background remains unchanged.LeviFiction wrote:Here Terrypin, I've removed the JascUtils requirement. See if this one works any better for you.
Code: Select all
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Executing NewDrawingObject
Executing NodeEditOffset
Executing NodeEditOffset
Executing VectorSelectNone
Colour: {'Color': (255, 1, 61), 'Pattern': None, 'Identity': u'Material', 'Texture': None, 'Gradient': None}
Width: 10
Specified: Number of lines
Border? Yes
Vertical Lines: 3
Horizontal Lines: 7
X Positions: [5, 362, 719, 1076, 1435]
Y Positions: [5, 278, 551, 824, 1097, 1370, 1643, 1916, 2195]
Code: Select all
from JascApp import *
import JascUtils
from Tkinter import *
import tkMessageBox
def ScriptProperties():
return {
'Author': 'Joe Fromm (idea by Diana Todd)',
'Copyright': 'Copyright (C) 2002-2003, Jasc Software Inc., All Rights Reserved. Permission to create derivate works of this script is granted provided this copyright notice is included',
'Description': 'Prompt for the number of cells in an image, and set the grid to match',
'Host': 'Paint Shop Pro',
'Host Version': '8.00'
}
class CellCountDlg(Frame):
''' define the dialog used to prompt the user for the number of cells'''
def __init__( self, parent, title ):
Frame.__init__(self, parent) # init our parent
# if we exit with OK this will be set to 1. A zero means we pressed cancel
self.OKPressed = 0
# define all the variables attached to the controls
self.GridLinesX = IntVar()
self.GridLinesX.set( 3 )
self.GridLinesY = IntVar()
self.GridLinesY.set( 3 )
# define the basics of the window
self.pack(expand=YES, fill=BOTH)
self.master.title('Define Cells')
# put some explanatory text on the window
Label( self, text = 'Enter the number of cells to have in the grid.\n'
'The default gridline color will be used.',
justify=LEFT ).pack(expand=YES, fill=BOTH, side=TOP)
# make a subframe to hold the cells across controls
XFrame = Frame( self )
XLabel = Label( XFrame, text='Cells across:', width=30 )
XLabel.pack( expand=YES, fill=BOTH, side=LEFT )
self.XEntry = Entry( XFrame, textvariable=self.GridLinesX )
self.XEntry.pack( expand=YES, fill=BOTH, side=RIGHT )
XFrame.pack(side=TOP)
# do the same thing for the cells down controls
YFrame = Frame( self )
YLabel = Label( YFrame, text='Cells down:', width=30 )
YLabel.pack( expand=YES, fill=BOTH, side=LEFT )
self.YEntry = Entry( YFrame, textvariable=self.GridLinesY )
self.YEntry.pack( expand=YES, fill=BOTH, side=RIGHT )
YFrame.pack(side=TOP)
# put OK/Cancel buttons on the dialog - parts of this lifted from TkSimpleDialog
ButtonFrame = Frame(self)
OKButton = Button( ButtonFrame, text="OK", width=10,
command=self.OnOK, default=ACTIVE )
OKButton.pack(side=LEFT, padx=5, pady=5)
CancelButton = Button( ButtonFrame, text="Cancel", width=10,
command=self.OnCancel )
CancelButton.pack(side=LEFT, padx=5, pady=5)
ButtonFrame.pack()
self.bind("<Return>", self.OnOK)
self.bind("<Escape>", self.OnCancel)
def OnOK(self, event=None):
''' called by pressing the OK button - validates data, and if no error
sets a good return code and dismisses the dialog by calling OnCancel
'''
try:
X = self.GridLinesX.get()
except ValueError:
X = 0
try:
Y = self.GridLinesY.get()
except ValueError:
Y = 0
if X < 1 or X > App.TargetDocument.Width - 1:
App.Do( GlobalEnv, 'StartForeignWindow', { 'WindowHandle': 0 } )
tkMessageBox.showerror( 'Cells across invalid',
'Cells across must be between 1 and %d' % (App.TargetDocument.Width - 1) )
App.Do( GlobalEnv, 'StartForeignWindow', { 'WindowHandle': int(self.winfo_id()) } )
return
if Y < 1 or Y > App.TargetDocument.Height - 1:
App.Do( GlobalEnv, 'StartForeignWindow', { 'WindowHandle': 0 } )
tkMessageBox.showerror( 'Cells down invalid',
'Cells down must be between 1 and %d' % (App.TargetDocument.Height - 1) )
App.Do( GlobalEnv, 'StartForeignWindow', { 'WindowHandle': int(self.winfo_id()) } )
return
# if we got here we passed validation
self.OKPressed = 1
# finish by pressing the Cancel button
self.OnCancel()
def OnCancel(self, event=None):
# on cancel we simply terminate the message loop
self.quit()
def Do(Environment):
global GlobalEnv
GlobalEnv = Environment
if JascUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
return
# create the root TK window
root = Tk()
# create the dialog and show the dialog
Dlg = CellCountDlg( root, 'Enter Cells')
# tell PSP that a foreign dialog is running. This causes PSP to do some additional
# work to keep the UI updating properly and to prevent the script window from going
# behind PSP.
App.Do( Environment, 'StartForeignWindow', { 'WindowHandle': int(root.winfo_id()) } )
root.mainloop()
App.Do( Environment, 'StartForeignWindow', { 'WindowHandle': 0 } )
root.destroy()
# if the user pressed cancel in the dialog just return
if not Dlg.OKPressed:
print 'Cancel pressed - aborting'
return
# get the number of cells to use
CellsAcross = Dlg.GridLinesX.get()
CellsDown = Dlg.GridLinesY.get()
# now divide those into the height and width to get the of the grid -
# any errors will accumulate on the right and bottom sides
GridSpacingX = App.TargetDocument.Width / CellsAcross
GridSpacingY = App.TargetDocument.Height / CellsDown
print 'Setting grid for %d horizontally, %d vertically' % ( GridSpacingX, GridSpacingY)
App.Do( Environment, 'GridGuideSnapProperties', {
'CurrentHorzGridSpacing': GridSpacingX,
'CurrentVertGridSpacing': GridSpacingY,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})
# turn on the grid
App.Do( Environment, 'ShowGrid', {
'ShowGrid': App.Constants.ShowCommands.Show,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})