Auto Leading scripting error (unknown attribute?)
i've been working on script lot of community here. thankful of it.
i have run bug. script run on text layers. script perform tasks of depends on whether or not leading set (auto) or user defined setting. worked great until morning when came across instance told me there error in code (line marked in red) , there no such attribute layer. particular text layer set auto leading. if converted specific leading , auto script work, of course don't want every time come across this.
any ideas, o' scripting community?
a snippet of script:
var doc = activedocument
var lay = doc.activelayer
var textsize = lay.textitem.size
var textlayer = doc.activelayer
var myfont = app.fonts.getbyname(textlayer.textitem.font).name;
var textheight = textlayer.bounds[3]-textlayer.bounds[1]
var textwidth = textlayer.bounds[2]-textlayer.bounds[0]
var docheight = doc.height
docheight = docheight.tostring().replace(' px', '');
var docwidth = doc.width
docwidth = docwidth.tostring().replace(' px', '');
var speclayname = lay.name
var docname = doc.name
var tempdoc = """temp file script"""
// set leading offset
var ogheight = getboundingbox(textsize, multiplier);
var leadoffset = ogheight;
// convert auto leading?
{// ========================================
if (lay.textitem.useautoleading == false){
var leadoffset = activedocument.activelayer.textitem.leading
{if (confirm('can convert auto leading you?'))
{
// make snapshot======================
var idmk = charidtotypeid( "mk " );
var desc61 = new actiondescriptor();
var idnull = charidtotypeid( "null" );
var ref28 = new actionreference();
var idsnps = charidtotypeid( "snps" );
ref28.putclass( idsnps );
desc61.putreference( idnull, ref28 );
var idfrom = charidtotypeid( "from" );
var ref29 = new actionreference();
var idhsts = charidtotypeid( "hsts" );
var idcrnh = charidtotypeid( "crnh" );
ref29.putproperty( idhsts, idcrnh );
desc61.putreference( idfrom, ref29 );
executeaction( idmk, desc61, dialogmodes.no );
alert ("i created history snapshot if need revert custom "+(activedocument.activelayer.textitem.leading) +" leading.");
lay.textitem.useautoleading = true
var leadoffset = ogheight}
}}
}
fyi: omitted brevity here realized important include it
var multiplier = 1.1823
var descfraction = 0.207
}
// functions define bounding boxes
{
function getboundingbox(textsize, multiplier) {
return math.round(textsize * multiplier);
}
function getheightabovebaseline(textsize, multiplier, descfraction) {
var boundingboxheight = getboundingbox(textsize, multiplier);
return math.round(boundingboxheight - (boundingboxheight * descfraction));
}
function getheightbelowbaseline(textsize, multiplier, descfraction) {
return math.round(getboundingbox(textsize, multiplier) * descfraction);
}
function getspectextheight(textsize) {
return math.round(textsize * 0.5);
}
}
More discussions in Photoshop Scripting
adobe
Comments
Post a Comment