PDA

View Full Version : PS Scripting Q


mercphoto
May-03-2004, 06:37 PM
Have a scripting question for Photo Shop CS. I'm trying to add a text box for a copyright notice. I can get the text box up, with text. But I can't seem to control where the box goes. How can I get my scrip to locate the box where I want it to be?

Apple Script examples are nice, but I'll take VB or Java and translate myself.

cletus
May-04-2004, 05:53 AM
Have a scripting question for Photo Shop CS. I'm trying to add a text box for a copyright notice. I can get the text box up, with text. But I can't seem to control where the box goes. How can I get my scrip to locate the box where I want it to be?

Apple Script examples are nice, but I'll take VB or Java and translate myself. mercphoto,

I'm not sure what you mean by a text box. Which if any of the following do you mean?



A dialog with text inside it
A text box (called an EditText element in Java Script) inside a dialog
A rectangular area in a photoshop image into which you place text
There is an example in the Photoshop CS Java Script Reference Guide (http://partners.adobe.com/asn/photoshop/scripting/docs/JavaScriptReferenceGuide.pdf) (page 21 of the PDF) that shows how to position a dialog box and how to position an EditText element.

Dialog
The parameters that specify the dialog's location (and size) are highlighted.
var dlg = new Window('dialog','Alert Box Builder', [100,100,480,245]);
dlg.msgPnl = dlg.add('panel',[25,15,355,130], 'Messages');
dlg.msgPnl.titleSt = dlg.msgPnl.add('statictext',[15,15,105,35],'Alert box title:');
dlg.msgPnl.titleEt = dlg.msgPnl.add('edittext',[115, 15, 315, 35],'Sample Alert');
dlg.msgPnl.msgSt = dlg.msgPnl.add('statictext', [15,65,105,85], 'Alert message:');
dlg.msgPnl.msgEt = dlg.msgPnl.add('edittext',[115, 45, 315, 105], '<your message here>', {multiline:true});
dlg.show();

Text Box Control (EditText Element)
The parameters that specify the edittext element's location (and size) are highlighted.
var dlg = new Window('dialog','Alert Box Builder', [100,100,480,245]);
dlg.msgPnl = dlg.add('panel',[25,15,355,130], 'Messages');
dlg.msgPnl.titleSt = dlg.msgPnl.add('statictext',[15,15,105,35],'Alert box title:');
dlg.msgPnl.titleEt = dlg.msgPnl.add('edittext',[115, 15, 315, 35],'Sample Alert');
dlg.msgPnl.msgSt = dlg.msgPnl.add('statictext', [15,65,105,85], 'Alert message:');
dlg.msgPnl.msgEt = dlg.msgPnl.add('edittext',[115, 45, 315, 105], '<your message here>', {multiline:true});
dlg.show();



I'll try to come up with an example of how to position a rectangular area in a photoshop image.


Oh, and by the way...


Welcome to dgrin!

cletus
May-04-2004, 08:09 AM
Ok, here is the sample code for positioning a filled box in a Photoshop image.

var fillColor = new SolidColor;
fillColor.rgb.red = 255;
fillColor.rgb.green = 255;
fillColor.rgb.blue = 0;

var selRegion = Array(Array(60,36),
Array(252,36),
Array(252,84),
Array(60,84),
Array(60,36));

docRef.selection.select(selRegion,SelectionType.RE PLACE);

var selRef = docRef.selection;

selRef.fill( fillColor, ColorBlendMode.NORMAL, 100, false );

The values used to define the selection region are in pixels.

hutchman
May-04-2004, 10:22 PM
Maybe I'm all wet on this one, but can't you just select the text layer and use the Free Transform tool to move it anywhere you want?//?

Hutch

cletus
May-05-2004, 05:32 AM
Maybe I'm all wet on this one, but can't you just select the text layer and use the Free Transform tool to move it anywhere you want?//?

Hutch
For the most part :nod

If mercphoto was trying to go for a look like this http://ab0wa.smugmug.com/photos/3976202-M.jpg
with the text inside (or on top of) a filled rectangle, you could use the free transform tool to move the text and box. First you would have to link the layers in the layers palette:http://ab0wa.smugmug.com/photos/3976201-M.jpg
Then the Free Transform tool would affect both layers at the same time. If you just wanted to move the text and rectangle, the Move tool would be a better choice though.

The benefit of positioning the text (and box) in a script is that it doesn't require user intervention.

mercphoto
May-05-2004, 06:03 AM
First, thanks for all the replies. Yes, I can use the hand tool to move it manually, but the point of the script is I want this placed AUTOMATICALLY.

I'm pasting in part of my script. I'm trying to take an 8x12 image, reduce the image to 6x9, make the canvas 8x10, then put an art layer as a text object below the image for a copyright notice. I can figure out everything except how to position the text object where I want it to be.


set isLandscape to true
set x_image to 9
set y_image to 6

set x_canvas to 10
set y_canvas to 8

tell application "Adobe Photoshop CS"
set ruler units of settings to inch units
set type units of settings to point units
set point size of settings to postscript size

set documentCount to count every document
set counter to 0

repeat with counter from 1 to documentCount
set current document to document counter

set x to width of current document as inches
set y to height of current document as inches

-- we have an image, must be 8x12 or 12x8
-- if not, exit
if (y > 8) then
-- we have a portrait picture
set isLandscape to false
set x_image to 6
set y_image to 9
set x_canvas to 8
set y_canvas to 10
set y_text to 9.2
set textWidth to 6
end if

-- Set text box to be .25" below image, centered. Width of
-- text box is width of image. Box is 1" from left side
set x_text to 1
set y_text to y_image + (0.75 * (y_canvas - y_image))
set textWidth to x_image

resize image current document width x_image height y_image
resize canvas current document width x_canvas height y_canvas

set textLayer to make new art layer in current document with properties {kind:text layer}
set size of text object of textLayer to 12
set justification of text object of textLayer to center
set contents of text object of textLayer to "Copyright (c) 2004 Bill Jurasz, mercphoto.smugmug.com"
-- set width of text object of textLayer to textWidth

end repeat

end tell

cletus
May-05-2004, 06:55 AM
First, thanks for all the replies. Yes, I can use the hand tool to move it manually, but the point of the script is I want this placed AUTOMATICALLY.

I'm pasting in part of my script. I'm trying to take an 8x12 image, reduce the image to 6x9, make the canvas 8x10, then put an art layer as a text object below the image for a copyright notice. I can figure out everything except how to position the text object where I want it to be.
Bill,

Have you tried this?


.
.
.
set textLayer to make new art layer in current document with properties {kind:text layer}
set size of text object of textLayer to 12
set justification of text object of textLayer to center
set position of text object of textLayer to {10,7}
set contents of text object of textLayer to "Copyright (c) 2004 Bill Jurasz,
mercphoto.smugmug.com"
.
.
.

mercphoto
May-05-2004, 07:42 AM
Bill,

Have you tried this?
set position of text object of textLayer to {10,7}


Yes, and that partially works. It is located correctly in the veritical direction (i.e under the photo), but not horizontally. Its also not centered, because the text layer is only as wide as the text itself.

Also I tried to do a "set width of text object of textLayer to 9" only to get an error that the fuction only applies to "paragraph text". Not sure what that means, but could shed additional light on the problem.

mercphoto
May-05-2004, 07:57 AM
Not sure why, but this works. I think the secret was the x-location being the dead-center horizontally, and then center justify. The location seems to be bound to the justification point.

Thanks for all the clues! It pointed me in the right direction.

set x_text to x_canvas / 2
set y_text to y_image + (0.75 * (y_canvas - y_image))
set textWidth to x_image

resize image current document width x_image height y_image
resize canvas current document width x_canvas height y_canvas

set textLayer to make new art layer in current document with properties {kind:text layer}
set size of text object of textLayer to 12
set justification of text object of textLayer to center
set position of text object of textLayer to {x_text, y_text}
set contents of text object of textLayer to "Copyright (c) 2004 Bill Jurasz, mercphoto.smugmug.com"