Highlighted

InDesign set differnt tabstops in different paragraphs

New Here ,
Apr 12, 2020

Copy link to clipboard

Copied

Hi all!

I'm trying to put a list of tabs in different consecutive paragraphs. I mean each paragraph will have its own tablist. But with the follow script (a main part of it) it keeps always the last tabs and put them to all paragraps. So if I have two paragraphs, the first has the same tabs with second. I think that it must be a way to solve it, because I tried to do that manually with few tabs in a few paragraphs and it worked.

I would appreciate it if someone could give me a solution. I tried it manually with paragraph style, but again I didn't succeed. Thanks in advance!

//----------------------------------------------------------------------------------------------------------

var myDocument = app.activeDocument;
var myTextFrame_Poi = myDocument.layers.item("Text").textFrames.item(1);
var my_Poi_Lines =myTextFrame_Poi.parentStory.lines.everyItem().getElements();

for (i = 0; i < myMusicTextObject.lines.length; i++) {
my_Poi_Lines[i+2].tabStops.everyItem().remove();
for (j = 0; j < myMusicTextObject.lines.item(i).words.length; j++) {
my_Poi_Lines[i+2].tabStops.add();
var tabstops= my_Poi_Lines[i+2].tabStops;
tabstops[0].alignment = TabStopAlignment.CENTER_ALIGN;
tabstops[0].position = myTabList_Pos[i, j];
//tabstops[1].remove;
}
}

//--------------------------------------------------------------------------------------------------------------

I think it probably won't help you fix your code. I described it only by my own imagination.

 

スクリーンショット 2020-04-15 11.48.02.png

 

var myDocument = app.activeDocument
var myMusicTextObject = myDocument.layers.itemByName("Blue").textFrames[0]; //Provisional settings
var myTextFrame_Poi = myDocument.layers.itemByName("Red").textFrames[0]; //Provisional settings
var myTabList_Pos = [], myLinePos, myWord, myPos, myPara;

//app.scriptPreferences.measurementUnit = 
var myLines = myMusicTextObject.parentStory.lines;
for(var i = 0; i < myLines.length; i++){
    myLinePos = [];
    for(var j = 0; j < myLines[i].words.length; j++){
        myWord = myLines[i].words[j];
        myPos = (myWord.insertionPoints[0].horizontalOffset //Provisional settings
                    + myWord.insertionPoints[-1].horizontalOffset) / 2
                    - myWord.parentTextFrames[0].geometricBounds[1];
        myLinePos.push(myPos);
        }
    myTabList_Pos.push(myLinePos);
    }

while(myTextFrame_Poi.parentStory.paragraphs.length < myTabList_Pos.length){
    myTextFrame_Poi.parentStory.contents += "\r";
    }
myPara = myTextFrame_Poi.parentStory.paragraphs;
for(i = 0; i < myTabList_Pos.length; i++){
    myPara[i].tabStops.everyItem().remove();
    for(j = 0; j < myTabList_Pos[i].length; j++){
        myPara[i].tabStops.add({position : myTabList_Pos[i][j], alignment : TabStopAlignment.CENTER_ALIGN});
        myPara[i].contents = "\ti" + myPara[i].contents; //Provisional settings
        }
    }

 

TOPICS
Scripting

Views

824

Likes

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

InDesign set differnt tabstops in different paragraphs

New Here ,
Apr 12, 2020

Copy link to clipboard

Copied

Hi all!

I'm trying to put a list of tabs in different consecutive paragraphs. I mean each paragraph will have its own tablist. But with the follow script (a main part of it) it keeps always the last tabs and put them to all paragraps. So if I have two paragraphs, the first has the same tabs with second. I think that it must be a way to solve it, because I tried to do that manually with few tabs in a few paragraphs and it worked.

I would appreciate it if someone could give me a solution. I tried it manually with paragraph style, but again I didn't succeed. Thanks in advance!

//----------------------------------------------------------------------------------------------------------

var myDocument = app.activeDocument;
var myTextFrame_Poi = myDocument.layers.item("Text").textFrames.item(1);
var my_Poi_Lines =myTextFrame_Poi.parentStory.lines.everyItem().getElements();

for (i = 0; i < myMusicTextObject.lines.length; i++) {
my_Poi_Lines[i+2].tabStops.everyItem().remove();
for (j = 0; j < myMusicTextObject.lines.item(i).words.length; j++) {
my_Poi_Lines[i+2].tabStops.add();
var tabstops= my_Poi_Lines[i+2].tabStops;
tabstops[0].alignment = TabStopAlignment.CENTER_ALIGN;
tabstops[0].position = myTabList_Pos[i, j];
//tabstops[1].remove;
}
}

//--------------------------------------------------------------------------------------------------------------

I think it probably won't help you fix your code. I described it only by my own imagination.

 

スクリーンショット 2020-04-15 11.48.02.png

 

var myDocument = app.activeDocument
var myMusicTextObject = myDocument.layers.itemByName("Blue").textFrames[0]; //Provisional settings
var myTextFrame_Poi = myDocument.layers.itemByName("Red").textFrames[0]; //Provisional settings
var myTabList_Pos = [], myLinePos, myWord, myPos, myPara;

//app.scriptPreferences.measurementUnit = 
var myLines = myMusicTextObject.parentStory.lines;
for(var i = 0; i < myLines.length; i++){
    myLinePos = [];
    for(var j = 0; j < myLines[i].words.length; j++){
        myWord = myLines[i].words[j];
        myPos = (myWord.insertionPoints[0].horizontalOffset //Provisional settings
                    + myWord.insertionPoints[-1].horizontalOffset) / 2
                    - myWord.parentTextFrames[0].geometricBounds[1];
        myLinePos.push(myPos);
        }
    myTabList_Pos.push(myLinePos);
    }

while(myTextFrame_Poi.parentStory.paragraphs.length < myTabList_Pos.length){
    myTextFrame_Poi.parentStory.contents += "\r";
    }
myPara = myTextFrame_Poi.parentStory.paragraphs;
for(i = 0; i < myTabList_Pos.length; i++){
    myPara[i].tabStops.everyItem().remove();
    for(j = 0; j < myTabList_Pos[i].length; j++){
        myPara[i].tabStops.add({position : myTabList_Pos[i][j], alignment : TabStopAlignment.CENTER_ALIGN});
        myPara[i].contents = "\ti" + myPara[i].contents; //Provisional settings
        }
    }

 

TOPICS
Scripting

Views

825

Likes

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
Apr 12, 2020 0
Enthusiast ,
Apr 12, 2020

Copy link to clipboard

Copied

There are a few things you do not understand.
What are the suddenly appearing variables "myMusicTextObject" and "myTabList_Pos"?
Why loop over lines instead of paragraphs? If the next line was a continuous paragraph, tabstops would be added at the same position.

Likes

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
Reply
Loading...
Apr 12, 2020 0
New Here ,
Apr 13, 2020

Copy link to clipboard

Copied

I am sorry. The paragraphs are one-line paragraphs. Ιn my attempt to solve the problem I replaced the word paragraphs with the word lines. I tried also: var my_Poi_Lines =myTextFrame_Poi.parentStory.paragraphs.everyItem().getElements();

but the result is the same. In my previous post I said that I give a main part of the code and not all, for practical reasons. "myMusicTextObject" comes from a selection from another layer and the length gives a specific number for the loop and "myTabList_Pos" is an array of numbers. Each line of this array is a list of tabs positions corresponds to each paragraph-line. So the problem is that with the previous code each paragraph does not have its own tabs but the tabs of the last paragraph replace the tabs of the other paragraphs. Forgive me but I hope I made you understand what I mean! if you need more explanations, of course I can give them to you!

Likes

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
Reply
Loading...
Apr 13, 2020 0
Enthusiast ,
Apr 13, 2020

Copy link to clipboard

Copied

Apparently you are wanting to set a tab stop for every word in every paragraph of a story. So let me ask:

Where is myMusicTextObject defined? Where is myTabList defined? 

Why are you using line instead of paragraph in 

var my_poi_Lines=myTextFrame_Poi.parentStory.lines.everyItem().getElements();

Why use the [i + 2] factor if you are setting tabs for each consecutive paragraph? If you want to start with paragraph 3 change the for statement to read for (i = 2; i < my_Poi_Lines.length; i++);

You can also make tthe code easier to read by establishing a variable (maybe myPara) to represent each paragraph within the i loop, Then use that variable instead of my_Poi_Lines[i].
//inside i loop
var mypara = my_Poi_Lines[i];
myPara.tabStops.everyIttem().remove();
var myTabRecord = []
  for (j = 0; j < myPara.words.length; j++) {
    myTabRecord.push {position:myTabList[i,j],alignment:TabStopAlignment.CENTER_ALIGN};
  }
myPara.tabList=myTabRecord;

}//end i loop

 

Not tested but hope this helps.

Likes

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
Reply
Loading...
Apr 13, 2020 0
Adobe Community Professional ,
Apr 14, 2020

Copy link to clipboard

Copied

Hi Terry,

best also show some screenshots with hidden characters visible:

One of the current text.

One of the desired text.

Tab panel also showing.

 

Thanks,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Apr 14, 2020 0
New Here ,
Apr 14, 2020

Copy link to clipboard

Copied

Unfortunately it didn't work. All paragraphs have the tabs of the last paragraph as before ... But at least you understood what I wanted to do and I hope that a solution will be found now.

I try to match the words of these paragraphs with the words of a text that is in another "layer" in the same document and come from text selection. I give some screenshots below as an example to understand. The blue "layer" has the text “Hello...”. The red "layer" will have the new text. My cursor is in the first empty paragraph and Tab panel is empty.

 

TerryTheostav_0-1586870892712.png

 

I choose the text in the blue "layer" (myMusicTextObject) in order to take the x-position and calculate the middle. That will be myTabList.

TerryTheostav_1-1586870892741.png

 

I run the script and as you can see below, the first tabs of the first line-paragraph are the same with the tabs of the second line-paragraph.

TerryTheostav_2-1586870892766.png

 

They have been replaced with the tabs of the second paragraph. If the text on the blue "layer" had more lines you would see that all the lines-paragraphs of the red level have the tabs of the last one and do not keep their own!

I hope that a solution will be found now.  It’s very important for me because i have hundreds of pages like these. I appreciate your willingness to help me!

 

 

Likes

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
Reply
Loading...
Apr 14, 2020 0
Enthusiast ,
Apr 14, 2020

Copy link to clipboard

Copied

Hello, Terry
Your post seems to be a translation of your language into English and is very difficult to understand. I am translating that English text into my language and reading ...

Could you please send a screenshot that created the desired state "without running the script" ?

I think it's better to clarify what you want to do than what causes the script to not work properly.

 

I understand that the words on the second line of the text in the blue layer is the basis for the tab in the text in the red layer.

Likes

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
Reply
Loading...
Apr 14, 2020 0
Enthusiast ,
Apr 14, 2020

Copy link to clipboard

Copied

I think it probably won't help you fix your code. I described it only by my own imagination.

 

スクリーンショット 2020-04-15 11.48.02.png

 

var myDocument = app.activeDocument
var myMusicTextObject = myDocument.layers.itemByName("Blue").textFrames[0]; //Provisional settings
var myTextFrame_Poi = myDocument.layers.itemByName("Red").textFrames[0]; //Provisional settings
var myTabList_Pos = [], myLinePos, myWord, myPos, myPara;

//app.scriptPreferences.measurementUnit = 
var myLines = myMusicTextObject.parentStory.lines;
for(var i = 0; i < myLines.length; i++){
    myLinePos = [];
    for(var j = 0; j < myLines[i].words.length; j++){
        myWord = myLines[i].words[j];
        myPos = (myWord.insertionPoints[0].horizontalOffset //Provisional settings
                    + myWord.insertionPoints[-1].horizontalOffset) / 2
                    - myWord.parentTextFrames[0].geometricBounds[1];
        myLinePos.push(myPos);
        }
    myTabList_Pos.push(myLinePos);
    }

while(myTextFrame_Poi.parentStory.paragraphs.length < myTabList_Pos.length){
    myTextFrame_Poi.parentStory.contents += "\r";
    }
myPara = myTextFrame_Poi.parentStory.paragraphs;
for(i = 0; i < myTabList_Pos.length; i++){
    myPara[i].tabStops.everyItem().remove();
    for(j = 0; j < myTabList_Pos[i].length; j++){
        myPara[i].tabStops.add({position : myTabList_Pos[i][j], alignment : TabStopAlignment.CENTER_ALIGN});
        myPara[i].contents = "\ti" + myPara[i].contents; //Provisional settings
        }
    }

 

Likes

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
Reply
Loading...
Apr 14, 2020 1
New Here ,
Apr 15, 2020

Copy link to clipboard

Copied

I’ m terribly sorry. You are right regarding the translation and you have guessed correctly what I am after. Most importantly, the code you gave me works and does exactly what I want. Sorry for the confusion. Many thanks!!

Likes

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
Reply
Loading...
Apr 15, 2020 0
ajabon LATEST
Enthusiast ,
Apr 15, 2020

Copy link to clipboard

Copied

I'm glad you helped!

Likes

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
Reply
Loading...
Apr 15, 2020 0