When I use this code
textLayer.textItem.justification
It shows some error:
Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop
Why in some file is ok , in some file is failed?
you can download the file here:
https://www.dropbox.com/s/e5p0foxlyx3rn9k/JM-2SG22684-F.psd
can you help me to have a look at it?
I downloaded the PSD four of the text layers fail with that message in CS6, CS5 and CS2. I have none of those two fonts on my machine. One of the layer that works has the same font as the four that fail. Have no idea the layers that fail are named "Event", "AT 2 P.M.", "Address and RSVP" and "Host"
If I double click on these layers text layers to update the text the just click on the justerfy to the right the to the align to the left and commit them all is well???
Doesn't make any difference for me Mike, textItem.position is always the same and the text does start at that position. I must be missing something?
//#target photoshop
var FontName = "Arial";
var FontSize = 14;
var black = new SolidColor();
black.rgb.hexValue = '000000';
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.documents.add(600,400,72,"Justification Example");
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = black;
newTextLayer.textItem.font = FontName;
newTextLayer.textItem.size = FontSize;
newTextLayer.textItem.contents = "The quick brown fox jumps over the lazy dog!";
newTextLayer.textItem.position = Array(20, 20);
newTextLayer.textItem.justification=Justification.CENTERJUSTIFIED;
$.writeln(newTextLayer.textItem.position);
app.documents.add(600,400,72,"Justification Example");
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = black;
newTextLayer.textItem.font = FontName;
newTextLayer.textItem.size = FontSize;
newTextLayer.textItem.contents = "The quick brown fox jumps over the lazy dog!";
newTextLayer.textItem.position = Array(20, 20);
newTextLayer.textItem.justification=Justification.LEFTJUSTIFIED;
$.writeln(newTextLayer.textItem.position);
app.documents.add(600,400,72,"Justification Example");
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = black;
newTextLayer.textItem.font = FontName;
newTextLayer.textItem.size = FontSize;
newTextLayer.textItem.contents = "The quick brown fox jumps over the lazy dog!";
newTextLayer.textItem.position = Array(20, 20);
newTextLayer.textItem.justification=Justification.RIGHTJUSTIFIED;
$.writeln(newTextLayer.textItem.position);
Paul… knock the word JUSTIFIED off each of your samples i.e. use just LEFT, RIGHT & CENTRE… This is what I meant in my previous post… What you have is JUSTIFIED type where left, right & centre are just how the last paragraph is treated… does that make sence? Sorry my painting is getting bad ( a couple of beers watching footy )
Muppet Mark wrote:
Paul, what I noticed is your script does NOT fail nor kick any error but if you look at the paragraph palette nothing is highlighted…
That is why I put as expected in parentheses. The justified enums don't throw an error with point text they just don't do what one would expect. And as Mark pointed out it seems to confuse the Photoshop text tool options and the pargraph panel when you apply those via a script to a point text layer( you can't apply them in the GUI, they are greyed out ).
And another question.
see my demo:
function exportData() {
try{
doSomething();
} catch(e) {
alert(e);
return;
}
}
function doSomething(){
try {
var align = textLayer.textItem.justification.toString().replace(/Justification./, '');
} catch (e) {
var align = 'LEFT';
}
}
exportData();
the queuestion is:
when doSomething catch an error, why exportData can catch the error too? Is it possible that exportData shouldn't catch the error.
I had a look at your sample file but I also don't have the fonts used so I could not test getting the justification.
I am not sure I understand your last question. I would think that the try/catch for var align = textLayer.textItem.justification.toString().replace(/Justification./, ''); is catching the same error that started this thread. I don't understand where 'exportData' comes from.
North America
Europe, Middle East and Africa
Asia Pacific