Copy link to clipboard
Copied
Hi everyone,
I am currently working with InDesign CS2 files and i want to find all text frames and change its first baseline offset to "Cap Height". So I have tried the below syntax and it shows error. Please help me for this.
THanks in advance
//==================
#target InDesign4.0
var myFrame = app.activeDocument.textFrame.everyItem();
for (var i=0; i<myFrame.length; i++){
myFrame.textFramePreferences.firstBaselineOffset=1296255087;
}
alert ('DONE');
//==================
Regards
Thiyagu
var myFrame = app.activeDocument.textFrames.everyItem().getElements();
for (var i=0; i<myFrame.length; i++){
myFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
}
alert ('DONE');
Copy link to clipboard
Copied
var myFrame = app.activeDocument.textFrames.everyItem().getElements();
for (var i=0; i<myFrame.length; i++){
myFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
}
alert ('DONE');
Copy link to clipboard
Copied
Hi Harbs,
Its working fine. Thank you so much for your valuable and kind suppport.
Regards
Thiyagu
Copy link to clipboard
Copied
What is the difference between the following two lines?
var myFrame = app.activeDocument.textFrames;
and
var myFrame = app.activeDocument.textFrames.everyItem().getElements();
In both cases the script works as expected. Why do you add .everyItem().getElements()?
Kasyan
Copy link to clipboard
Copied
Because everyItem().getElements() builds a static Array of the items.
Without it, it's a dynamic collection.
When you have a collection, there has to be interaction with InDesign
every time you access a member of the collection and InDesign rebuilds
the collection each time it's accessed. That means a lot of extra
overhead.
Bottom line: using a static array is almost always faster than using
collections.
Harbs
Copy link to clipboard
Copied
Thank you , Harbs. Now everything is clear to me.
Kasyan
Copy link to clipboard
Copied
One important exception to this rule is with Text objects. With Text objects, I've found Collections to be more efficient than Arrays.
I think the reason for this is because Text objects don't really exist on the C++ level. Any time you access a Text object with scripting, InDesign must resolve that object within the whole text strand (which involves at least as much overhead as resolving the Collection). Page Items (and most other objects) on the other hand are basically mapped straight to the C++ ones so they don't need to be resolved in the same way.
Harbs
Copy link to clipboard
Copied
If you literally want all text frames, including any that are part of a group or inline/anchored to another story, then you need to use:
myPIs = app.activeDocument.allPageItems;
for (var j = myPIs.length - 1; j >= 0; j--) {
if (myPIs
myPIs
myPIs
}
}
Dave
Copy link to clipboard
Copied
Hi Dave,
Its working fantastic. Thank you so much for your valuable and kind suppport.
Thiyagu
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more