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

  1. from JascApp import *
  2. import JascUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': 'Linda Nieuwenstein',
  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': 'The the current image and split to CMYK, putting the separate channels back as layers in a layer group.',
  9.         'Host': 'Paint Shop Pro',
  10.         'Host Version': '8.00'
  11.         }
  12.  
  13. def Do(Environment):
  14.     if JascUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  15.         return
  16.     
  17.     # keep track of the doc we are starting with
  18.     TargetDoc = App.TargetDocument
  19.     
  20.     # start by splitting the current image.
  21.     App.Do( Environment, 'SplitToCMYK', {
  22.             'GeneralSettings': {
  23.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  24.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  25.                 }
  26.             })
  27.  
  28.     # the split created 4 new documents and puts them at the end of the open list.
  29.     # make a four element list that we can reorder.  At this point we don't
  30.     # care about the contents, just that it has four elements
  31.     NewDocs = App.Documents[-4:]                # grab the last four docs
  32.           
  33.     # now loop over the four newest docs.
  34.     for ChannelDoc in App.Documents[-4:]:
  35.         Name = ChannelDoc.Title
  36.         if Name.find( 'Black' ) != -1:
  37.           NewDocs[0] = ChannelDoc # make Black first
  38.         elif Name.find( 'Yellow' ) != -1:
  39.           NewDocs[1] = ChannelDoc # make Yellow next
  40.         elif Name.find( 'Magenta' ) != -1:
  41.           NewDocs[2] = ChannelDoc # then Magenta
  42.         elif Name.find( 'Cyan' ) != -1:
  43.           NewDocs[3] = ChannelDoc # make Cyan last
  44.     
  45.     FirstChannel = App.Constants.Boolean.true   # need special handling on the first one
  46.     
  47.     # We use explicit specification of which document to work on by adding a fourth
  48.     # parameter to the App.Do call.  For operations on one of the single channel
  49.     # images we use one of the saved docs.  For operations on the original doc we use
  50.     # the saved TargetDoc.
  51.     for Doc in NewDocs:  
  52.         # this shouldn't be necessary, but at the moment paste as new layer has a bug,
  53.         # so we promote manually.  This assumes the original image is RGB.
  54.         App.Do( Environment, 'IncreaseColorsTo16Million', {}, Doc )
  55.         
  56.         # copy it to the clipboard        
  57.         App.Do( Environment, 'Copy', {}, Doc  )
  58.         
  59.         # paste it into the existing document - note the specification of target doc
  60.         App.Do( Environment, 'PasteAsNewLayer', {}, TargetDoc )
  61.  
  62.         # when we pasted it the layer came in as Raster Layer n, and we want to know what
  63.         # channel it represents, so pick up the image title and use that to determine
  64.         # the layer name.  Out of split to CMYK the image will be named CyanN, YellowN, MagentaN, and BlackN.
  65.         NewLayerName = Doc.Title
  66.         if NewLayerName.find( 'Black' ) != -1:
  67.             NewLayerName = 'Black Channel'
  68.         elif NewLayerName.find( 'Yellow' ) != -1:
  69.             NewLayerName = 'Yellow Channel'
  70.         elif NewLayerName.find( 'Magenta' ) != -1:
  71.             NewLayerName = 'Magenta Channel'
  72.         else:
  73.             NewLayerName = 'Cyan Channel'
  74.             
  75.         # now that we have the layer name, rename it
  76.         App.Do( Environment, 'LayerProperties', {
  77.                 'General': {
  78.                     'Name': NewLayerName, 
  79.                     }, 
  80.                 'GeneralSettings': {
  81.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  82.                     'AutoActionMode': App.Constants.AutoActionMode.Default
  83.                     }
  84.                 }, TargetDoc )
  85.         
  86.         # we want the channels to end up inside of a layer group, so after we
  87.         # paste the first channel in create a layer group to hold it, and then select
  88.         # the layer inside the group so subsequent creates go where we want them.
  89.         if FirstChannel == App.Constants.Boolean.true:
  90.             FirstChannel = App.Constants.Boolean.false
  91.  
  92.             # create the layer group
  93.             App.Do( Environment, 'NewLayerGroup', {
  94.                     'General': {
  95.                         'Name': 'CMYK Channels', 
  96.                         }, 
  97.                     'GeneralSettings': {
  98.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  99.                         'AutoActionMode': App.Constants.AutoActionMode.Match
  100.                         }
  101.                     }, TargetDoc )
  102.  
  103.             # select the member of the group rather than the group itself            
  104.             NewLayer = App.Do( Environment, 'SelectLayer', {
  105.                     'Path': (0,0,[1],App.Constants.Boolean.false), 
  106.                     'GeneralSettings': {
  107.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  108.                         'AutoActionMode': App.Constants.AutoActionMode.Default
  109.                         }
  110.                     }, TargetDoc)
  111.             
  112.         # do the close in silent mode since we don't want to save changes                
  113.         App.Do( Environment, 'FileClose', {
  114.                 'GeneralSettings': {
  115.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  116.                     'AutoActionMode': App.Constants.AutoActionMode.Match
  117.                     }
  118.                 }, Doc )