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

linked text frame in enumeration

Participant ,
Feb 27, 2015 Feb 27, 2015

in one document there are many embedded text frame (object style applied = "myObjSty1")

I want to write increasing numbers

I tried to write but did not

Can you help me in this regard

Thank you in advance

var sNo = 1;

var doc = app.activeDocument; 

app.findGrepPreferences = app.changeGrepPreferences = null; 

app.findGrepPreferences.findWhat = "~a"; 

var found = doc.findGrep(); 

for(var i =found.length-1;i>=0;i--)

{

if(found.allPageItems[0].appliedObjectStyle == myObjSty1)

{

     found.texts[0].select();

     app.changeGrepPreferences.changeTo = (++sNo);

     app.selection[0].changeGrep();

}

}

TOPICS
Scripting
920
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

Community Expert , Feb 28, 2015 Feb 28, 2015

1. You have to set the if clause inside the for loop.

2. You need to address every single text frame by its index

3. You need a counter to advance every time a match is found

//Object style is named "MyObjectStyle1"

//It is not nested in an ObjectStyleGroup !!

var myObjSty1 = app.documents[0].objectStyles.itemByName("MyObjectStyle1");

//Selection is the text frame or some text of the story you want to get the anchored text frames:

var myStory = app.selection[0].parentStory;

//Collecting ALL ancho

...
Translate
Community Expert ,
Feb 27, 2015 Feb 27, 2015

@handifem – you made several assumptions here not spoken out, when I am looking at your code (and reading about what you are trying to accomplish here). I might be wrong, but:

What kind of sequence would you like to see?

Order of anchored text frames in one single story?

That would be: myStory.textFrames by their index numbers.

Geometrical order throughout the story depending on their position on the page?

Throughout the document?

Something else?

A GREP Search with "~a" may find the anchors representing the anchored text frames in a totally different order you would like to see.

If we know something more, I think, we can help with the code as well.

Uwe

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
Participant ,
Feb 28, 2015 Feb 28, 2015

Text in the fluid

anchored text frame (and applied them to the object style)

in which "1" is writing. delete "1"

to enumerate them, respectively,

aaaa1.jpg

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
Community Expert ,
Feb 28, 2015 Feb 28, 2015

@handifem – ah, ok. This is the easy case of sequence.

You need no GREP search for this, simply iterate through all text frames of the story.

Here an example where I assume, that are no other text frames anchored to the story that would not need numbering:

var myStory = app.selection[0].parentStory;

var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements();

for(var n=0;n<myAnchoredTextFrames.length;n++){

    myAnchoredTextFrames.texts[0].contents = String(n+1);

    };

Of course you could decorate it with an if clause to single out all text frames with a specific object style.

Uwe

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
Participant ,
Feb 28, 2015 Feb 28, 2015

I could not connect to an object style

To enumerate all frames

var myStory = app.selection[0].parentStory; 

var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements(); 

if(myAnchoredTextFrames.appliedObjectStyle == myObjSty1){ //?

for(var n=0;n<myAnchoredTextFrames.length;n++){ 

    myAnchoredTextFrames.texts[0].contents = String(n+1); 

    }

};

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
Community Expert ,
Feb 28, 2015 Feb 28, 2015

1. You have to set the if clause inside the for loop.

2. You need to address every single text frame by its index

3. You need a counter to advance every time a match is found

//Object style is named "MyObjectStyle1"

//It is not nested in an ObjectStyleGroup !!

var myObjSty1 = app.documents[0].objectStyles.itemByName("MyObjectStyle1");

//Selection is the text frame or some text of the story you want to get the anchored text frames:

var myStory = app.selection[0].parentStory;

//Collecting ALL anchored text frames of the story to an array:

var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements();

//Define a start number:

var myStartNumber = 1;

//Loop through the array of the text frames anchored:

for(var n=0;n<myAnchoredTextFrames.length;n++){

  

    //If my object style is assigned to the individual anchored text frame in that array:

    if(myAnchoredTextFrames.appliedObjectStyle == myObjSty1){

        //Set the contents to its text to the String of the current value of the start number variable

        myAnchoredTextFrames.texts[0].contents = String(myStartNumber);

        //If that is done, change the current number by adding the number 1:

        myStartNumber = myStartNumber + 1;

        };

    };

Uwe

PS.: You should really look more into the basics for JavaScript before doing more work in ExtendScript.

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
Enthusiast ,
Feb 28, 2015 Feb 28, 2015

Hi Guys,

although this seems to be answered a idea for a nonscripting way:

1. Create a paragraph style with autonumbering in a separate textframe with Autosize > width only.

2. Insert your textframe with the numbers

3. Write your text, add or delete some numbers, half way done

4. You will maybe discover a problem, that is shown in my screenshot. Sometimes the textframes and the followed character are overlapping. I think this is a bug.

5. Solution: Create a shortcut for "Recompose all stories immediately". After refreshing the document everything is fine, so no script needed

1.png

2.png

3.png

4.png

–Kai

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
Enthusiast ,
Feb 28, 2015 Feb 28, 2015
LATEST

After a further test: It seems that 'recompose' is not necessary, if the textframes column have a fixed width (to hold 2 or 3 numbers) and 'Autosize' is turned off.

Bildschirmfoto 2015-02-28 um 19.01.36.png

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