Adobe 23101335 - Photoshop - PC Manual Download Page 91

Photoshop 7.0 Scripting Guide

91

Index

Stroking the selection border 69
subroutines 20
superclass 10
System requirements 6

JavaScript 7
Mac 7
Windows 7

T

Text item object 64

setting fonts 66
setting text stroke colors 66
setting the contents 65
warping text 67

Text values 12, 13

U

Units 44

AppleScript Length Unit Values 45
Changing ruler and type units 48
command parameters that take unit values 47
object properties that depend on unit values 46
special unit value types 46

V

Value types

array 13
boolean 12, 13
double 13
integer 12
list 12
long 13
number 12
real 12
record 12
reference 12, 13
string 12, 13
text 12, 13

Variable 14
Variables

Assigning values to 14

Naming variables 15

Viewing Photoshop objects, commands and methods 34

AppleScript dictionary 34

Viewing Photoshop ojects, commands and methods

Visual Basic type library 35

Visual Basic

Object Browser 35

Visual Basic Values 13

W

Warping text 67
Web Safe Color 79
Windows Scripting Host 7

Summary of Contents for 23101335 - Photoshop - PC

Page 1: ...ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose CA 95110 2704 408 536 6000 http partners adobe com bbc March 2002 Photoshop 7 0 Scripting Guide...

Page 2: ...The software described in this document is furnished under license and may only be used or copied in accordance with the terms of such license Adobe Photoshop and PostScript are either registered tra...

Page 3: ...objects 9 2 2 Object model concepts 9 2 3 Documenting scripts 11 2 4 Values 12 2 5 Variables 14 2 6 Operators 16 2 7 Commands and methods 17 2 8 Handlers subroutines and functions 20 2 9 The Scripts m...

Page 4: ...s 3 8 Document object 54 3 9 Layer objects 58 3 10 Text item object 64 3 11 Selections 67 3 12 Working with Filters 74 3 13 Channel object 75 3 14 Color objects 77 3 15 History object 80 3 16 Clipboar...

Page 5: ...snippets that will not work as fully functional scripts Several conventions will be used when referring to AppleScript Visual Basic and JavaScript Please note the following shortcut notations AS stand...

Page 6: ...th short simple scripts to save a few seconds a day and move on to more involved scripts Any repetitive task is a good candidate for a script Once you can identify the steps and conditions involved in...

Page 7: ...asic or one of the applications that contains a Visual Basic editor Most Windows systems include the Windows Scripting Host If you do not have Windows Scripting Host or would like more information abo...

Page 8: ...n be used to script Photoshop On Windows any language which is COM aware can be used to script Photoshop This includes languages available in Windows Scripting Host such as VBScript and JScript as wel...

Page 9: ...ontext Here s a way to think about objects and their properties as an object model Imagine that you live in a house that responds to your commands The house is an object and its properties might inclu...

Page 10: ...avaScript are objects contained within other objects For example rooms are elements or collections of our house contained within the house object In Photoshop documents are elements of the application...

Page 11: ...ur description For multiple line comments start your comment with the characters and end it with this is a single line comment this is a multiple line comment Visual Basic In Visual Basic enter Rem fo...

Page 12: ...t TABLE 2 1 AppleScript Values Value type What it is Example boolean Logical true or false true integer Whole numbers no decimal points Integers can be positive or negative 14 real A number which may...

Page 13: ...Array A list of values Arrays contain a single value type unless the type is defined as Variant Array 10 0 20 0 30 0 40 0 Object reference A specific reference to an object appRef ActiveDocument TABLE...

Page 14: ...pt however it is considered good form to declare all of your variables before using them To declare variables in Visual Basic use the Dim keyword To declare variables in JavaScript use the var keyword...

Page 15: ...t reference use Set Set thisLayer appRef Photoshop ActiveDocument ArtLayers 1 If you are trying to assign a value to a variable in Visual Basic that is not an object reference do not use Set Use Visua...

Page 16: ...returned would be 10 25 You can also use operators to perform comparisons equal to not equal to greater than or less than etc Some operators differ between AppleScript Visual Basic and JavaScript Cons...

Page 17: ...erties and the assignment operator to retrieve and change object properties JS In JavaScript use the add method to create new objects and the assignment operator to assign both object references and v...

Page 18: ...hotoshop documents open 2 7 2 Control structures Control structures provide for repetitive processes or loops The idea of a loop is to repeat some action with or without changes each time through the...

Page 19: ...at until flag true set flag to button returned of display dialog Quit buttons Yes No Yes end repeat set flag to false repeat while flag false set flag to button returned of display dialog Later button...

Page 20: ...an refer to from within your script These subroutines provide a way to re use parts of scripts Typically you send one or more values to a subroutine and it returns one or more values There s nothing s...

Page 21: ...are in the Scripts folder 2 9 1 Scripts folder The Scripts folder is in the Photoshop Presets folder This folder is created during Scripting Support functionality installation All JavaScript files pla...

Page 22: ...ript Debugging on page 26 for more information There is also a Browse button in the Scripts dialog When this button is clicked a file navigation dialog will be presented Use this dialog to locate and...

Page 23: ...cript will be checked when compiled it is possible to create and compile scripts in AppleScript that will not run properly The Script Editor Application doesn t have extensive debugging tools but it d...

Page 24: ...lay the contents of one or more variables in the log window by using the log command log myVariable otherVariable In addition the Result window choose Controls Show Result will display the value from...

Page 25: ...next line of your script or choose Run Start or press F5 to continue normal execution of the script You can also observe the values of variables defined in your script using the Watch window a very v...

Page 26: ...the Run Script button changes to Debug Script When invoking JavaScript from AppleScript or VB you must set the show debugger argument appropriately If you set show debugger to never you will disable...

Page 27: ...his view changes the current scope enabling you to inspect and modify scope specific data All debugging output appears in the upper right pane of the script debugger window The currently executing Jav...

Page 28: ...ndows Halt the currently executing script temporarily and reactivate the script debugger window This button is enabled when a script is running Stop Cmd K Mac OS Ctrl K Windows Stop execution of the s...

Page 29: ...ield Photoshop executes the contents of the command line entry field within the stack scope of the line highlighted in the Stack Trace view The command line entry field accepts any JavaScript code mak...

Page 30: ...avaScript code Temporary breakpoints The Script Breakpoints window provides the following controls The Line field contains the line number of the breakpoint within the scriptlet The Condition field ma...

Page 31: ...og Found My Document on error display dialog Couldn t locate document My Document end try end tell VB Private Sub Command1_Click Store a reference to the document with the name My Document If the docu...

Page 32: ...0 Scripting Guide 32 Scripting basics Testing and troubleshooting 2 JS try for i 0 i documents length i var myName documents i name alert myName catch someError alert JavaScript error occured Message...

Page 33: ...s by name rather than numeric index and set the current document in your script before working on it Document numbers do not represent their stacking order See 3 4 Object references on page 42 for mor...

Page 34: ...s JavaScript does not include an object browser 3 2 1 Viewing Photoshop s AppleScript dictionary 1 Start Photoshop then your Script Editor 2 In Script Editor choose File Open Dictionary Script Editor...

Page 35: ...p 7 0 Object Library option from the list of available references and click the OK button If the library does not appear in the list of available references then Scripting Support is not installed pro...

Page 36: ...peration of the script and it s good style to include them in your own scripts As you look through the script you ll see how to create then address each object The AppleScript command tell indicates t...

Page 37: ...rt Visual Basic and create a new project Add the Adobe Photoshop 7 0 Object Library reference to the project as shown earlier If you are using a built in editor in a VBA application skip to step 4 2 A...

Page 38: ...pRef Preferences RulerUnits psInches Create a new 4x4 inch document and assign it to a variable Dim docRef As Photoshop Document Dim artLayerRef As Photoshop ArtLayer Dim textItemRef As Photoshop Text...

Page 39: ...e VBScript is not as strongly typed as Visual basic In Visual Basic you say Dim aRef as Photoshop ArtLayer in VBScript you say Dim aRef For VBScript simply omit the as X part VBScript does not support...

Page 40: ...nces RulerUnits 2 Create a new 4x4 inch document and assign it to a variable Dim docRef Dim artLayerRef Dim textItemRef Set docRef appRef Documents Add 4 4 Create a new art layer containing text Set a...

Page 41: ...lerUnits Units INCHES Create a new 4x4 inch document and assign it to a variable var docRef documents add 4 4 Create a new art layer containing text var artLayerRef docRef artLayers add artLayerRef ki...

Page 42: ...esult of manipulating other objects For example when a new art layer is created in the document it will become the first layer and the layer that was previously the first layer is now the 2nd layer Th...

Page 43: ...erences RulerUnits appRef Preferences RulerUnits psInches Set docRef appRef Documents Add 4 4 72 My New Document Create 2 new layers and store their return references Set layer1Ref docRef ArtLayers Ad...

Page 44: ...ferences the way you provide a unit value in a script will depend on the language you are using All languages support plain numbers for unit values Scripting Support treats these values as being of th...

Page 45: ...es settings are measured by ppi The length unit value types available AppleScript use are listed below The points and picas unit value types are PostScript points with 72 points per inch The tradition...

Page 46: ...following script will result in an error set pixelValue to pixels 72 Next line will result in a coercion error when run set inchValue to pixelValue as inches 3 5 2 Unit value useage The following two...

Page 47: ...sual Basic JavaScript crop bounds height width Document Crop Bounds Height Width document crop bounds height width resize canvas height width Document ResizeCanvas Height Width document resizeCanvas h...

Page 48: ...ttings to postscript size In Visual Basic and JavaScript ruler units and type units are properties of the Preferences accessed through the application object s preferences property as shown below VB a...

Page 49: ...nts parameter The parameter takes an array for you to pass any values For example save the following JavaScript in a file somewhere on your machine alert You passed arguments length arguments for i 0...

Page 50: ...avaScript debugger at the beginning of your JavaScript When you use this option the JavaScript command debugger will stop the JavaScript and display the JavaScript debugger 3 6 2 Executing one line Ja...

Page 51: ...et the current or active document before executing any other commands To do this use the current document ActiveDocument activeDocument property on the application object AS set docRef to current docu...

Page 52: ...an error to the script See section 2 10 4 Error handling on page 31 for more information on catching errors Opening a document When using the open command there are a number of specifiable options Th...

Page 53: ...ptions raw format Options RawFormatOpenOptions RawFormatOpenOptions The following example shows how to open a generic PDF document AS tell application Adobe Photoshop 7 0 set myFilePath to alias a fil...

Page 54: ...to open var fileRef new File a file path Create a PDF option object var pdfOpenOptions new PDFOpenOptions pdfOpenOptions antiAlias true pdfOpenOptions height 100 pdfOpenOptions width 200 pdfOpenOption...

Page 55: ...s may not always be applicable It also means that many of the option values do not have well defined default values The best way to determine what values can or should be used for save is to perform a...

Page 56: ...tte MatteType NONE jpgSaveOptions quality 1 activeDocument saveAs jpgFile jpgSaveOptions true Extension LOWERCASE 3 8 2 Document information A Photoshop document can be associated with additional info...

Page 57: ...resize image current document width 4 height 4 VB docRef ResizeImage 4 4 JS docRef resizeImage 4 4 Resizing the canvas is done similarly AS resize canvas current document width 4 height 4 VB docRef R...

Page 58: ...ers art layer and layer set Both types of layers have common properties such as visible The common attributes are placed in a general layer class that both art layer and layer set inherits from When y...

Page 59: ...e used with the fill command Dim colorObj As Photoshop SolidColor Set colorObj CreateObject Photoshop SolidColor colorObj RGB Red 255 colorObj RGB Green 100 colorObj RGB Blue 0 Now apply fill to the c...

Page 60: ...ll be created at the beginning of the document Dim newLayerSetRef As Photoshop LayerSet Set newLayerSetRef appRef ActiveDocument LayerSets Add Move the new layer to after the first layer newLayerSetRe...

Page 61: ...yers can be moved into layer sets The following examples show how to create a layer set duplicate an existing layer and move the duplicate layer into the layer set AS set current document to document...

Page 62: ...rs Scripting also supports linking and unlinking layers You may want to link layers together so that moving or transforming them can be done with one statement To link layers together do the following...

Page 63: ...r named L1 NOTE The layer styles name is case sensitive AS apply layer style art layer L1 of current document using Puzzle Image VB docRef ArtLayers L1 ApplyStyle Puzzle Image JS docRef artLayers L1 a...

Page 64: ...f docRef artLayers add newLayerRef kind LayerKind TEXT To check if an existing layer is a text layer you must compare the layer s kind to text layer psTextLayer LayerKind TEXT AS if kind of layerRef i...

Page 65: ...the contents of the text item To set the contents of a text item in AppleScript you would write set contents of text item of art layer Layer 1 of current document to Hello If you use a text item obje...

Page 66: ...20 magenta 50 yellow 30 black 0 VB Set newColor CreateObject Photoshop SolidColor newColor CMYK Cyan 20 newColor CMYK Magenta 100 newColor CMYK Yellow 30 newColor CMYK Black 0 textLayerRef TextItem Co...

Page 67: ...ommon effect that can be applied to text To warp a text item object set the object s warp style WarpStyle warpStyle property The style to set it to is an enumeration AS set warp style of textItemRef t...

Page 68: ...ther selection types are diminished extended and intersected The diminished type will shrink the current selection the extended selection type will grow the current selection and the intersected type...

Page 69: ...rUnits originalRulerUnits JS remember unit settings and set to values expected by this script var originalRulerUnits preferences rulerUnits preferences rulerUnits Units PIXELS get selection and replac...

Page 70: ...1 4 Expand contract and feather selections These three commands are used to change the size of the selection The values are passed in ruler units the value of which are stored in Photoshop preferences...

Page 71: ...ences rulerUnits preferences rulerUnits Units PIXELS var selRef activeDocument selection selRef expand 5 selRef contract 5 selRef feather 5 restore unit setting preferences rulerUnits originalRulerUni...

Page 72: ...ent document VB selRef Fill docRef HistoryStates 10 JS selRef fill activeDocument historyStates 9 3 11 6 Rotating selections You can rotate either the contents of a selection or the selection boundary...

Page 73: ...ument into channel My Channel of current document combination type extended VB selRef Store docRef Channels My Channel psExtendSelection JS selRef store docRef channels My Channel SelectionType EXTEND...

Page 74: ...eans that prior to running a filter you may have to set the active channels Since more than one channel can be active at a time you must provide an array of channels when setting a channel The code be...

Page 75: ...ge its kind or change the current channel selection 3 13 1 Channel types In addition to the component channels Photoshop lets you to create additional channels You can create a spot color channel a ma...

Page 76: ...ay docRef channels 0 docRef channels 2 docRef activeChannels theChannels Deleting a component will change the document to a multi channel document 3 13 3 Creating new channels You can create three dif...

Page 77: ...set the foreground color you should create a SolidColor object set its color model by assigning the color model values and then set the foreground color to the solid color Here s how VB solidColor Cr...

Page 78: ...trieve the hex value In Visual Basic and JavaScript the RGBColor object has a string property called HexValue hexValue 3 14 2 Getting and converting colors Here s how to get the foreground color in Ap...

Page 79: ...ally equal to each other and false otherwise The examples below compare the foreground color to the background color AS if equal colors foreground color with background color then VB If appRef Foregro...

Page 80: ...cRef HistoryStates 1 JS docRef activeHistoryState docRef historyStates 0 The code above sets the current history state to the top history state that is in the History palette Using history states in t...

Page 81: ...information on working with selections 3 16 Clipboard interaction The clipboard commands in Photoshop Scripting Support operate on layers and selections The commands can be used to operate on a single...

Page 82: ...opy merged selection of current document In VB and JS pass true for the Merged parameter of the Copy methods VB docRef Selection Copy True JS docRef selection copy true 3 16 3 Cut The Cut command oper...

Page 83: ...set current document to document Doc2 set newLayerRef to paste In Visual Basic and JavaScript the paste command is defined on the Document object VB appRef ActiveDocument appRef Documents Doc2 Set ne...

Page 84: ...o the actions that you perform from the UI The Windows version of ScriptingListener creates the following 2 files C ScriptingListenerJS log contains JavaScript code corresponding to the actions that a...

Page 85: ...aScript code from the ScriptingListenerJS log file to another file and substitute the filter values with variable names In the following we have wrapped the code in a JavaScript function and replaced...

Page 86: ...ipt values from JavaScript For example change the Emboss JavaScript shown in the previous section to the following and save it in a file called Emboss js function emboss angle height amount var id32 c...

Page 87: ...ollection emboss arguments 0 arguments 1 arguments 2 From VBScript you can then run the Emboss filter by saying Set objApp CreateObject Photoshop Application objApp DoJavaScriptFile C Emboss js Array...

Page 88: ...jApp SET objApp CreateObject Photoshop Application DIM id19 id19 objApp CharIDToTypeID Embs DIM desc4 SET desc4 CreateObject Photoshop ActionDescriptor DIM id20 id20 objApp CharIDToTypeID Angl Call de...

Page 89: ...alues 78 Setting a Color 77 web safe colors 79 COM 8 Command and methods JavaScript 17 Commands and methods 17 AppleScript 17 Visual Basic 17 Comments in scripts 11 AppleScript 11 JavaScript 11 Visual...

Page 90: ...r collections 10 Object inheritance 10 Object reference 10 12 13 Object references 42 AppleScript 42 Visual Basic and JavaScript 43 Opening a document 52 Operators 16 Other scripting languages 8 P Pho...

Page 91: ...that take unit values 47 object properties that depend on unit values 46 special unit value types 46 V Value types array 13 boolean 12 13 double 13 integer 12 list 12 long 13 number 12 real 12 record...

Reviews: