Copy link to clipboard
Copied
Hi experts,
my script like this:
function movecashline()
{
var
mMsg = {title: "move frames"},
cMH, cMV, cZP, cRO;
cash();
function cash ()
{
var
mTarget = checkSelection().everyItem().getElements(),
mDoc, cMPages, cPages, cPage;
mMsg.funName = "Main";
while (mDoc = mTarget.pop()) {
doRulesUp(mDoc);
cMPages = mDoc.masterSpreads.everyItem().pages.everyItem().getElements();
cPages = mDoc.pages.everyItem().getElements();
while (cPage = cMPages.pop())
moveBar (cPage);
while (cPage = cPages.pop())
moveBar (cPage);
doRulesDown(mDoc);
}
}
function moveBar (mPage, mStyle)
{
var
cTopMargin = mPage.marginPreferences.top,
cBottomMargin = mPage.marginPreferences.bottom,
cBounds = mPage.bounds,
cPI, cGB,
cStyleName = "footer",
cPIs = mPage.textFrames.everyItem().getElements();
while (cPI = cPIs.pop()) {
if (!cPI.hasOwnProperty ("texts")) continue;
if (!cPI.texts[0].characters.length) continue;
if (!cPI.texts[0].appliedParagraphStyle.name.match(/^footer$/i)) continue;
cGB = cPI.geometricBounds;
if (cGB[0] > cBounds[2] - cBottomMargin)
cPI.move([cGB[1], cBounds[2] + 25]);
else
cPI.move([cGB[1], -(cGB[2] - cGB[0]) - 25]);
}
}
function doRulesUp(cDoc)
{
with (cDoc.viewPreferences) {
cMH = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
cMV = app.activeDocument.viewPreferences.verticalMeasurementUnits;
cRO = app.activeDocument.viewPreferences.rulerOrigin;
horizontalMeasurementUnits = MeasurementUnits.POINTS;
verticalMeasurementUnits = MeasurementUnits.POINTS;
rulerOrigin = RulerOrigin.PAGE_ORIGIN;
}
cZP =cDoc.zeroPoint,
cDoc.zeroPoint = [0,0];
}
function doRulesDown(cDoc)
{
with (cDoc.viewPreferences) {
horizontalMeasurementUnits = cMH;
verticalMeasurementUnits = cMV;
rulerOrigin = cRO;
}
cDoc.zeroPoint = cZP;
}
function checkSelection ()
{
mMsg.funName = "Check Selection";if ( !app.documents.length) {
mMsg.line = $.line - 1;
mMsg.text = "No target detected.\nOpen any doc.";
errorClose (mMsg);
}
return app.documents; //
}
}
aim to move the text frame, which has text and applied to para style "footer".
but it pop up error on this case:
if there is threaded frames, like this:
and the fame is empty
the error says:
error from this line:
if (!cPI.texts[0].characters.length) continue;
reason:
Object is invalid
could some one tell how to fix, please.
thanks
regard
John
In case of threaded frames, for 2nd textframe onwards, texts[0] is invalid when the textframe is empty. Hence your code fails, depending upon your use case you could modify your code as follows
if (!cPI.texts[0].isValid || !cPI.texts[0].characters.length) continue;
You could even identify if the textframe is a part of a thread by using the previousTextFrame property.
if(cPI.previousTextFrame != null)
alert("The textframe is part of a thread and is not the first textframe")
-Manan
Copy link to clipboard
Copied
In case of threaded frames, for 2nd textframe onwards, texts[0] is invalid when the textframe is empty. Hence your code fails, depending upon your use case you could modify your code as follows
if (!cPI.texts[0].isValid || !cPI.texts[0].characters.length) continue;
You could even identify if the textframe is a part of a thread by using the previousTextFrame property.
if(cPI.previousTextFrame != null)
alert("The textframe is part of a thread and is not the first textframe")
-Manan
Copy link to clipboard
Copied
Hi Manan
the error says:
Object does not support the property or medthod "isvalid"
after modify you code.
John
Copy link to clipboard
Copied
Sorry its a typo, its not isvalid but isValid
Copy link to clipboard
Copied
Thank you Man,
thanks so much.
John
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more