Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

find every text frame and set first baseline offset...

Explorer ,
May 26, 2009 May 26, 2009

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

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 26, 2009 May 26, 2009

var myFrame = app.activeDocument.textFrames.everyItem().getElements();

for (var i=0; i<myFrame.length; i++){
  myFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
}
alert ('DONE');

Translate
LEGEND ,
May 26, 2009 May 26, 2009

var myFrame = app.activeDocument.textFrames.everyItem().getElements();

for (var i=0; i<myFrame.length; i++){
  myFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
}
alert ('DONE');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2009 May 26, 2009

Hi Harbs,

Its working fine. Thank you so much for your valuable and kind suppport.

Regards

Thiyagu

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 28, 2009 May 28, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2009 May 28, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 28, 2009 May 28, 2009

Thank you , Harbs. Now everything is clear to me.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2009 May 28, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 26, 2009 May 26, 2009

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 instanceof TextFrame) {

          myPIs.textFramePreferences.firstBaselineOffset = FirstBaseline.capHeight;

          myPIs.textFramePreferences.minimumFirstBaselineOffset = 0;

     }

}

Dave

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2009 May 26, 2009

Hi Dave,

Its working fantastic. Thank you so much for your valuable and kind suppport.

Thiyagu

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines