Hi, what I am trying to do is have a script that will do something like this: http://www.agasyanc.ru/text-splitter
But it doesn't work in CS6, what do I have to do get this puppy working?
Thank you in advanced!
Text Splitter Script
-
hamstu
Text Splitter Script
Code: Select allvar doc = app.activeDocument;
var layer = doc.activeLayer;
var text = layer.textItem.contents;
var textArray = text.split("\r");
var pos = layer.textItem.position;
var leading = 0;
try {
if (layer.textItem.useAutoLeading) {
leading = layer.textItem.size/100*Math.round(layer.textItem.autoLeadingAmount);
}
else {
leading = Number(layer.textItem.leading)
}
} catch (e) {
leading = layer.textItem.size/100*Math.round(layer.textItem.autoLeadingAmount);
}
$.writeln ("Leading is " + leading);
layer.textItem.contents = textArray[0];
layer.name = textArray[0];
for (var k=1; k < textArray.length; k++){
var tmp = layer.duplicate();
tmp.textItem.position = [pos[0], pos[1]+(Number(leading)*k)]
tmp.textItem.contents = textArray[k];
}
The trick was adding a try/catch block around the code that checks the useAutoLeading property. For some reason this property returns undefined, but you can still get the autoLeadingAmount with no problems. I've got no idea why, maybe someone else knows.
var layer = doc.activeLayer;
var text = layer.textItem.contents;
var textArray = text.split("\r");
var pos = layer.textItem.position;
var leading = 0;
try {
if (layer.textItem.useAutoLeading) {
leading = layer.textItem.size/100*Math.round(layer.textItem.autoLeadingAmount);
}
else {
leading = Number(layer.textItem.leading)
}
} catch (e) {
leading = layer.textItem.size/100*Math.round(layer.textItem.autoLeadingAmount);
}
$.writeln ("Leading is " + leading);
layer.textItem.contents = textArray[0];
layer.name = textArray[0];
for (var k=1; k < textArray.length; k++){
var tmp = layer.duplicate();
tmp.textItem.position = [pos[0], pos[1]+(Number(leading)*k)]
tmp.textItem.contents = textArray[k];
}
The trick was adding a try/catch block around the code that checks the useAutoLeading property. For some reason this property returns undefined, but you can still get the autoLeadingAmount with no problems. I've got no idea why, maybe someone else knows.