Adobe 23101764 Scripting Guide - Page 41
Dim appRef As New Photoshop.Application
UPC - 718659340025
View all Adobe 23101764 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 41 highlights
Scripting Photoshop 3 Your first Photoshop script For now, enter the following code. The lines preceded by ' (single quotes) are comments, and will be ignored by the scripting system. They're included to describe the operation of the script. As you look through the script, you'll see how to create, then address each object. Private Sub Command1_Click() ' Hello World Script Dim appRef As New Photoshop.Application ' Remember current unit settings and then set units to ' the value expected by this script Dim originalRulerUnits As Photoshop.PsUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.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.TextItem Set docRef = appRef.Documents.Add(4, 4) ' Create a new art layer containing text Set artLayerRef = docRef.ArtLayers.Add artLayerRef.Kind = psTextLayer ' Set the contents of the text layer. Set textItemRef = artLayerRef.TextItem textItemRef.Contents = "Hello, World!" ' Restore unit setting appRef.Preferences.RulerUnits = originalRulerUnits End Sub 5. Save the form. 6. Start Photoshop. 7. Return to Visual Basic and run the program. If you created a form, click the button you created earlier. 8. Run the script. Photoshop will create a new document, add a new art layer, change the art layer's type to text and set the text to "Hello, World!" Photoshop CS Scripting Guide 37