home *** CD-ROM | disk | FTP | other *** search
/ PC Extra 07 & 08 / pca1507.iso / Software / psp8 / Data1.cab / CenterLayer.PspScript < prev    next >
Encoding:
Text File  |  2003-04-22  |  1.6 KB  |  39 lines

  1. from JascApp import *
  2. import JascUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': 'Joe Fromm',
  7.         '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',
  8.         'Description': 'Center the active layer on the canvas',
  9.         'Host': 'Paint Shop Pro 8',
  10.         'Host Version': '8.00'
  11.         }
  12.  
  13. def Do(Environment):
  14.     # we need a document for this to work
  15.     if JascUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.  
  18.      # need the canvas size, the layer size and the layer position
  19.     CanvasSize = App.TargetDocument.Size
  20.     LayerInfo = App.Do( Environment, 'ReturnLayerProperties' )
  21.     # LayerRect comes back as a tuple of the from ( (x,y), dx, dy )
  22.     # we want to work with a size tuple and a position tuple, so rearrange it.
  23.     LayerSize = (LayerInfo[ 'LayerRect' ][1], LayerInfo[ 'LayerRect' ][2] )
  24.     LayerPos =  LayerInfo[ 'LayerRect' ][0]
  25.     
  26.     # now compute how far to move the layer to get it centered
  27.     DesiredPos = ( (CanvasSize[0] - LayerSize[0]) / 2, (CanvasSize[1] - LayerSize[1]) / 2 )
  28.     Offset = ( DesiredPos[0] - LayerPos[0], DesiredPos[1] - LayerPos[1] )
  29.     App.Do( Environment, 'Mover', {
  30.             'Offset': Offset, 
  31.             'Object': App.Constants.LayerOrSelection.Layer, 
  32.             'SelectPoint': None,
  33.             'GeneralSettings': {
  34.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  35.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  36.                 }
  37.             })
  38.  
  39.