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

Find 'Nested Line Style' and insert frame

Contributor ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

Hi,

I'm trying to insert the identification tag at the end-of-line to the 'Nested Line Style' applied paragraph, but the below code insertion point position has been changed. What are the logical changes between the two codes? 

 

[[fine this code, taking time to write and execute]]

var mypg = app.activeDocument.pages;
for(var p=0; p<mypg.length; p++){
    var myTf = mypg[p].textFrames;
    for(var t=0; t<myTf.length; t++){
        var mypara = myTf[t].paragraphs;
        if(mypara.length>=2){}else{continue}
        for(var r=0; r<mypara.length; r++){
            if(mypara[r].nestedLineStyles.length>0){
                var myLine = mypara[r].lines[0].insertionPoints[-1];
                var myTxFrame = myLine.textFrames.add({geometricBounds:[0,0,20,100]});
                myTxFrame.texts[0].pointSize = "3";
                myTxFrame.contents = "<1linestyle>";
                myTxFrame.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED; 
            }
        }
    }
}

Screen Shot 2021-07-16 at 4.15.48 pm.png

 

 

 

 

[[working the wrong position, minimal writing and execution time too]] 

var mypg = app.activeDocument.pages.everyItem().textFrames.everyItem().paragraphs.everyItem().getElements();
for(var s=0; s<mypg.length; s++){
    if(mypg[s].nestedLineStyles.length>0){
        var myLine = mypg[s].lines[0].insertionPoints[-1];
        var myTxFrame = myLine.textFrames.add({geometricBounds:[0,0,20,100]});
        myTxFrame.texts[0].pointSize = "3"
        myTxFrame.contents = "<1linestyle>";
        myTxFrame.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
    }
}

Screen Shot 2021-07-16 at 4.17.23 pm.png

 

 

 

 

Thanks,

Selva

TOPICS
Scripting

Views

159

Translate

Translate

Report

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 , Jul 17, 2021 Jul 17, 2021

Selva -- I'm not surprised that the second script runs much quicker: it makes dramatically fewer calls to the DOM. And it could be quicker still: simply search the nested line style.

 

The best place for the tag's anchored frame is at the start of the paragraph with the nested style. You should first create an object style for the tag frames, and set the reference points and the X and Y offsets in order to place the frame exactly where you want them. It's confusing, by the way, to call an insert

...

Votes

Translate

Translate
Community Expert ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Hi Selva,

sorry, but what exactly is "the identification tag" ?

Why not using the first insertion point of the line after the nested line style?

You could check before how many lines are affected by the applied nested line style with property lineCount.

 

Hm. And first create the text frame on the spread, then anchor it to the insertion point.

See method insertAnchoredObject() of anchoredObjectSettings for text frames.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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 ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Selva -- I'm not surprised that the second script runs much quicker: it makes dramatically fewer calls to the DOM. And it could be quicker still: simply search the nested line style.

 

The best place for the tag's anchored frame is at the start of the paragraph with the nested style. You should first create an object style for the tag frames, and set the reference points and the X and Y offsets in order to place the frame exactly where you want them. It's confusing, by the way, to call an insertion point 'myLine'.

var myLine = mypg[s].lines[0].insertionPoints[-1];

So insert the anchored frame at the first insertion oint of the paragraph (or of the character style instance, if you search your nested style).

 

@Laubender:

> And first create the text frame on the spread, then anchor it to the insertion point.
> See method insertAnchoredObject() of anchoredObjectSettings for text frames.

 

Not really. insertAnchoredObject() is needed only when you want to move an existing frame into an insertion pont. When you add a frame, you can add it at an insertion point.

 

P.

Votes

Translate

Translate

Report

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 ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Hi Peter,

of course one could add a frame directly; just wanted to point out that there is a second option to anchor this frame.

 

And yes, your advice is very good to anchor the frame at the first insertion point of the first line. Because the first line could be hyphenated and anchoring a frame at the last insertion point of the first line will spoil the hyphenation.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Contributor ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

LATEST

Hi Uwe and Peter,

Thanks for your valuable comments.

 

I need to modify and test more. I'll get back to you once I succeed. 

 

 

Thanks,

Selva

Votes

Translate

Translate

Report

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