Article View: adobe.scripting.indesign
Article #462Re: CS3 JS flag which page has empty frame
From: Dave_Saunders
Date: Sat, 21 Mar 2009 13:05
Date: Sat, 21 Mar 2009 13:05
49 lines
2600 bytes
2600 bytes
I usually switch to spread coordinates to avoid those kinds of issues (although others swear by page coordinates). I use these two functions:
function saveMeasures(doc, units) {
var uPrefs = doc.viewPreferences;
var uMeasures = {
horiz:uPrefs.horizontalMeasurementUnits,
vert:uPrefs.verticalMeasurementUnits,
rule:uPrefs.rulerOrigin,
zp:doc.zeroPoint
}
doc.viewPreferences.properties = {
horizontalMeasurementUnits:units,
verticalMeasurementUnits:units,
rulerOrigin:RulerOrigin.spreadOrigin,
}
doc.zeroPoint = [0,0];
return uMeasures;
}
function restoreMeasures(doc, measures) {
doc.viewPreferences.properties = {
horizontalMeasurementUnits:measures.horiz,
verticalMeasurementUnits:measures.vert,
rulerOrigin:measures.rule
}
doc.zeroPoint = measures.zp;
}
I call these like this--notice the code is inside a function; that makes it possible to use return to exit the script which in turn makes it possible to call the restore function as I exit, using the return in two different places:
function splitElements(aDoc) {
var curPage = app.activeWindow.activePage;
var prevPage = aDoc.pages[curPage.documentOffset - 1];
if (prevPage === aDoc.pages[-1]) {
alert("Don't run this script on the first page of a document.");
return;
}
var uMeasures = saveMeasures(aDoc, MeasurementUnits.points);
var oSized = getOsetElement(prevPage);
if (oSized === null) return restoreMeasures(aDoc, uMeasures); // nothing to do
splitElement(oSized, prevPage, curPage, aDoc);
return restoreMeasures(aDoc, uMeasures);
}
This script needed to convert the measurement units to points because it needs to do calculations involving leading and stroke weights, both of which are provided in points.
Dave
Technical Details
Message-ID:
<59b83b3d.7@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossingReferences:
<59b83b3d.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,5f85c25f887dafb2 X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Dave_Saunders@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: CS3 JS flag which page has empty frame Message-ID: <59b83b3d.7@webcrossing.la2eafNXanI> Date: Sat, 21 Mar 2009 06:05:29 -0700 References: <59b83b3d.-1@webcrossing.la2eafNXanI> Lines: 61 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit