Copy link to clipboard
Copied
Hi Team,
Select the text by textstylerange, find the PostScript font name and change the font to the corresponding one.
Sample Input data shared below:
1. need to select text by textstylerange.
2. get postscript font name.
3. match with given input data (like as if gotham font found).
4. replace font with new one(matching respective column with next column, like as if found gotham font and need to replace kefa).
Thanks
Here's the code for the active text layer
//////////////////////////////////////////////////////
// define your csv-file
// headers must be: "Findfont" and "Replacefont", case sensitive and without spaces
var file = new File("C:\\1\\aaa.csv");
//////////////////////////////////////////////////////
// depending on the data in the csv-file, use the posrscipt name or just the name of the font.
// ex. "Arial-BoldMT" => fontPostScriptName, "Arial" => fontName
v
...
Copy link to clipboard
Copied
First point is not clear. I don't understand how and where you want to do that.
btw did you find your answer in your previous thread:
Find text and redefine font family name, style, size and leading.
(I'm asking as you did not respond for given answer of the other user)
Copy link to clipboard
Copied
Hi @Kukurykus ,
For point 1, select the text by text-style-range (A continuous range of identical text formatting attributes).
For above snap, style ranges are described. They have similar properties, but different in color.
Note: I found the result in the previous questions, which was very helpful to my study. But the given result did not exactly match my questions.
Please allow some time to respond, I have already mentioned this as my schedule. I will do it when everything is done.
Thanks for understanding.
Thanks
Copy link to clipboard
Copied
Here's the code for the active text layer
//////////////////////////////////////////////////////
// define your csv-file
// headers must be: "Findfont" and "Replacefont", case sensitive and without spaces
var file = new File("C:\\1\\aaa.csv");
//////////////////////////////////////////////////////
// depending on the data in the csv-file, use the posrscipt name or just the name of the font.
// ex. "Arial-BoldMT" => fontPostScriptName, "Arial" => fontName
var use_postscript_name = false;
//////////////////////////////////////////////////////
file.open("r");
var s = file.read();
file.close();
var data = csv_to_array(s);
replace_styles(activeDocument.activeLayer.id);
alert("done");
//////////////////////////////////////////////////////
function replace_styles(layer_id)
{
try {
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var textKey = executeActionGet(r).getObjectValue(stringIDToTypeID("textKey"));
var list = textKey.getList(stringIDToTypeID("textStyleRange"));
var new_list = new ActionList();
for (var i = 0; i < list.count; i++)
{
var d = list.getObjectValue(i);
var fr = d.getInteger(stringIDToTypeID("from"));
var to = d.getInteger(stringIDToTypeID("to"));
var st = d.getObjectValue(stringIDToTypeID("textStyle"));
var postscript_name = st.getString(stringIDToTypeID("fontPostScriptName"));
var font_name = st.getString(stringIDToTypeID("fontName"));
for (var x = 0; x < data.length; x++)
{
if (use_postscript_name)
{
if (postscript_name == data[x].Findfont)
{
st.putString(stringIDToTypeID("fontPostScriptName"), data[x].Replacefont);
st.erase(stringIDToTypeID("fontName"));
break;
}
}
else
{
if (font_name == data[x].Findfont)
{
st.putString(stringIDToTypeID("fontName"), data[x].Replacefont);
st.erase(stringIDToTypeID("fontPostScriptName"));
break;
}
}
}
var d = new ActionDescriptor();
d.putInteger(stringIDToTypeID("from"), fr);
d.putInteger(stringIDToTypeID("to"), to);
d.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), st);
new_list.putObject(stringIDToTypeID("textStyleRange"), d);
}
textKey.putList(stringIDToTypeID("textStyleRange"), new_list);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIdentifier(stringIDToTypeID("textLayer"), layer_id);
d.putReference(stringIDToTypeID("null"), r);
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), textKey);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch(e) { alert(e); }
}
//////////////////////////////////////////////////////
function csv_to_array(data, sep)
{
try {
if (sep == undefined) sep = /[;,]/;
var lines = data.split(/\r\n|\n/);
var headers = lines[0].split(sep);
var ret = new Array();
for (var i = 1; i < lines.length; i++)
{
var data = lines[i].split(sep);
if (data.length == headers.length)
{
var o = new Object();
for (var j = 0; j < headers.length; j++)
{
o[headers[j]] = data[j];
}
ret.push(o);
}
}
return ret;
}
catch(e) { alert(e); }
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied