Grid script

Moderator: Kathy_9

Post Reply
Joelle
Posts: 1815
Joined: Wed Apr 02, 2008 10:12 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Prime B350M-A
processor: AMD Ryzen 5 1500 Quad-Core
ram: 16 GB RAM
Video Card: NVidia GeForce GTX 1050
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: Samsung
Corel programs: PaintShop Pro X9
Location: UK

Grid script

Post by Joelle »

Made by Peter Anderson in 2007.

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...
Panda_Grid_v2-1.zip
(2.65 KiB) Downloaded 196 times
Joëlle
(PSPX9 )
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Grid script

Post by terrypin »

Your downoaded and unzipped script works fine here in PSP 2018 thanks Joëlle. Just as your emailed version did.

But unfortunately not in my ancient PSP 8.

Code: Select all

ImportError: No module named PSPUtils
PSP 8 is still my preference, due largely to familiarity over many years. So I'm wondering if anyone can suggest an edit please?

I'm also unsure how to proceed once I have the grid. My main aim is to allow fast pasting, so each image must not require exact positioning. But that discussion is probably not about scripting!
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
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: Grid script

Post by LeviFiction »

PSP Utils is just an extra library. Depending on how the script works it might easily be modified to not require PSP Utils
https://levifiction.wordpress.com/
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
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: Grid script

Post by LeviFiction »

Here Terrypin, I've removed the JascUtils requirement. See if this one works any better for you.
Attachments
Panda_Grid_v2-1.zip
(2.64 KiB) Downloaded 197 times
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Grid script

Post by terrypin »

LeviFiction wrote:Here Terrypin, I've removed the JascUtils requirement. See if this one works any better for you.
Thanks 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.

Interestingly, it also runs fine in PSP 2018.

BTW, note that to get say a 4 x 8 matrix (I'll not say 'grid' from now on, reserving that for the virtual inbuilt grid option), you have to specify 3 vertical and 7 horizontal lines and a border (That actually delivers 5 and 9 lines, including the outer borders.)

EDIT: In case it helps, here's a copy of the Script Output window:

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]
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Grid script

Post by terrypin »

The script GridByCells, which I assume was inbuilt, works in both PSP 8 and PSP 2018. I've shown its code below. But it uses the inbuilt grid feature and therefore sadly lacks a key feature of Panda_Grid_v2-1: setting the line width.

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
                }
            })

--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Post Reply