Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


find index value of enter mark

Explorer ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Hi All,

I am looking to find out enter mark index  for below line.

this below line associated with xml element 

i wanted to find out the index of that last enter through parentStory

pls suggest the line 

Please check Attachement.

Conflicts of interest are listed at the end of this article.enter index.png

TOPICS
Bug, EPUB, Scripting, Server developers

Views

169

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
community guidelines

correct answers 1 Correct answer

Explorer , Jul 09, 2021 Jul 09, 2021
Hi All,Thanks for your suggestionsI got the solution i tried following way function groupingElements(){ var myDoc=app.documents[0]; var endNodeFound = false; var allElements = []; var xPath = "//Article_Title"; var root = myDoc.xmlElements[0]; var node = null; var abstractNode = null; try { var proc = app.xmlRuleProcessors.add([xPath]); var match = proc.startProcessingRuleSet(root); while (match != undefined) { node = match.element; match = proc.findNextMatch(); if (node != null && node != undef...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Try this:

myXMLElement.texts[0].characters[-1].paragraphs[-1].characters[-1].index

where variable myXMLElement holds the xml element with that particular tag.

 

As you can see I jump to the last character of the text of that xml element which jumps too short.

But then I go for the last paragraph of the text of that xml element, look after the last character in that paragraph and return its index number that is relative to the parent story of the text.

 

Regards,
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
community guidelines
Explorer ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Hi,

thanks 

 

i am finding index and storing in a variable and then i wanted to move the element after that i wanrted to again on that index postion i have to add on enter how can i give that one.

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
community guidelines
Adobe Community Professional ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Hm. Sorry, I'm not clear what you want to do.

Could you show in screenshots with a before and after screenshot what you like to do?

Perhaps also showing the Story Editor panel with the tags and invisible characters.

 

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
community guidelines
Explorer ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Screenshot 2021-07-07 215141.png

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
community guidelines
Explorer ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Basically, when i am moving element from one place to anothet place then it is going but enter is left 

now i wanted to remove that enter and add theat enter to the same postion where my tag moved.

 

 

 

 

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
community guidelines
Adobe Community Professional ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

If I understand you correctly you say that you are moving the whole text of the tagged element to another place and that works fine just that the enter is not moved. Looking at your initial screenshot I think that the enter character is outside the tag maker, change the tag to include the enter character as well and your current code shall work without change.

-Manan

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
community guidelines
Explorer ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Hi 

thanks for reply.

Actually i am not able to undestand change the tag to include the enter character as well.

can you explain with any example.

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
community guidelines
Adobe Community Professional ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

When you tagged your text, you select the text and then apply the tag. Now in your screenshot, it shows that the selection while applying the tag did not include the enter character. So untag the text and then reselect all the content including the enter character and then apply the tag, that should hopefully make your code do what you want.

-Manan

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
community guidelines
Adobe Community Professional ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

Hi @nupmOjh@,

just to illustrate what I like to see from you, the tags are showing, the Story Editor is showing and invisible characters are showing as well:

 

TextWithTag-WhatShouldBeMovedWhereTo.PNG

 

Sorry, but I still can only guess what you like to do.

My example above is a bit more generic like yours.

With your example the tagged text is nearly consumes nearly all characters of all the one single paragraph.*

 

So: Would you like to move all paragraphs of the tagged text to somewhere else?

In my screenshot above of the xmlElement.texts[0] has two paragraphs. It's only one with your example.

 

And here comes the problem:

xmlElement.move( LocationOption, Text ) will only move texts[0] of the xmlElement.

 

The alternative, to move the paragraph or the paragraphs themselves does not work:

xmlElement.texts[0].paragraphs.everyItem().move( LocationOption, Text )

The tags will not be moved along with the text. And other strange things could happen.

 

Here one of my bad results where I tried to move the two paragraphs to the end of the story.

First argument of method move() was LocationOptions.AFTER , second argument was the last insertion point in the story. So InDesign missed by one character, the "?" now still is the last character of the story. But most important, the tags did not move at all:

 

TextWithTag-TwoParagraphsMoved-by-Script.PNG

 

 

If you do this in the GUI by drag and drop of selected text there is no issue at all:

TextWithTag-TwoParagraphsMoved-by-GUI.PNG

 

So, to sum this up, is it your aim to move all paragraphs of a given xmlElement.texts[0] to somewhere else?

Or am I on the wrong track at all?

 

Regards,
Uwe Laubender

( ACP )

 

* EDITED FOR CLARITY

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
community guidelines
Explorer ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

Hi @Laubender ,

i am  writing this script for indesign server version i am working on indesign server 2019 

actually tagged text is good option.

but the thing is that the element does not contains enter

now the enter is untag thats why it is not moving.

pls suggest me any option how can i tagged that one also before moving??

So: Would you like to move all paragraphs of the tagged text to somewhere else?

yes but with enter.

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
community guidelines
Adobe Community Professional ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

Alright.

BTW: If I say "paragraph" I always mean the whole paragraph, that includes the end of paragraph character, that Carriage Return ( Unicode 000D ), if there is one. And story.paragraphs[n] always gets you that character if there is one.

 

That aside, would a strategy be successful to move the paragraph(s) in pieces of text?

Or could there be a better way? Untagging text, moving paragraph, tagging text?

 

I would test algorithms like that with various variants of formatted text and also with a multiple of paragraphs where the start tag is in the middle of a paragraph and the end tag is also in the middle of a paragraph. Not necessarily the same paragraph like in my screenshot of my last post. And maybe also with paragraphs where more than one set of tags is applied.

 

Regards,
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
community guidelines
Explorer ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Hi All,

Thanks for your suggestions

I got the solution i tried following way

 

function groupingElements(){
var myDoc=app.documents[0];
var endNodeFound = false;
var allElements = [];
var xPath = "//Article_Title";
var root = myDoc.xmlElements[0];
var node = null;
var abstractNode = null;
try {
var proc = app.xmlRuleProcessors.add([xPath]);
var match = proc.startProcessingRuleSet(root);
while (match != undefined) {
node = match.element;
match = proc.findNextMatch();
if (node != null && node != undefined) {
for(var i = node.index; i < node.parent.xmlElements.length; i++){
if(node.parent.xmlElements[i].markupTag.name == "Abstract"){
abstractNode = node.parent.xmlElements[i];
endNodeFound = true;
break;
}
else{
allElements.push(node.parent.xmlElements[i]);
app.select(node.parent.xmlElements[i]);
}
}
if(endNodeFound && allElements.length > 0){
var newTagFM1 = node.parent.xmlElements.add("fm1");
newTagFM1 = newTagFM1.move(LocationOptions.AFTER, allElements[allElements.length-1]);
for(var x = allElements.length-1; x >= 0; x--){
allElements[x].select();
var enterMarkBefore = false;
var enterMarkAfter = false;
var style = allElements[x].insertionPoints[0].appliedParagraphStyle.name;
// if(allElements[x].insertionPoints[0].parent.characters[allElements[x].characters[-1].index+2].contents == "\r"){
if((allElements[x].markupTag.name != "Article_Subtitle") && allElements[x].characters[0].parent.characters[allElements[x].characters[-1].index+2].contents == "\r"){
// allElements[x].characters[0].parent.characters[enterimark].contents;
allElements[x].insertionPoints[0].parent.characters[allElements[x].characters[-1].index+2].contents = "";
enterMarkAfter = true;
}
//~ try{
//~ if(allElements[x].insertionPoints[0].parent.characters[allElements[x].characters[0].index-2].contents == "\r"){
//~ allElements[x].insertionPoints[0].parent.characters[allElements[x].characters[0].index-2].contents = "";
//~ enterMarkBefore = true;
//~ }
//~ }
//~ catch(e){}
var tempTag = allElements[x].move(LocationOptions.AT_BEGINNING, newTagFM1);
//~ if(enterMarkBefore){
//~ tempTag.insertTextAsContent("\r", XMLElementPosition.BEFORE_ELEMENT);
//~ }
if(enterMarkAfter){
tempTag.insertTextAsContent("\r", XMLElementPosition.AFTER_ELEMENT);
tempTag.texts[0].appliedParagraphStyle = style;
}

myDoc.recompose();

}

 

 

 

Thanks

Anupam

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
community guidelines
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

"i am writing this script for indesign server version"

 

Hi @nupmOjh@,

I do not think your code will run on InDesign Server if method select() is used.

With InDesign Desktop where one can use app.copy() app.paste() and text.select() your issue should be no problem at all. A script with five to ten lines perhaps.

 

Alright, I have to look that up with DOM documentation:

allElements[x].select()

Variable allElements is an array of xmlElements. DOM documentation for InDesign Desktop has method select() with object xmlElement, InDesign Server misses method select() as method for object xmlElement.

 

So I do not think your code will run successfully with InDesign Server.

DOM documentation for old InDesign Server CS6 can be found here:

http://www.jongware.com/idjshelp.html

Don't think that much changed in regards to object xmlElement since then…

 

Regards,
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
community guidelines
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Correct. select() doesn't work on InDesign Server.

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
community guidelines
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Thanks, Peter!

Now to solve the OP's issue in a different way I came up with moving that end-of-paragraph character inside the markup text, use move() with the xmlElement and finally move that character out.

 

On purpose I used some strange formatting of the source text. Some overrides on the applied paragraph style:

 

Solution-on-Page3.PNG

 

By all means the code I used is no general recipe for things like that; there are too many assumptions on the number of associatedXMLElements with the text etc.pp. But it is working with my sample document and also should work on InDesign Server:

 

var doc = app.documents[0];

var myXMLElement = doc.xmlElements[0].xmlElements[7].xmlElements[0];

// Get the text that is markup:
var myMarkupText = myXMLElement.texts[0];

// Identify the character that is outside of the markaup:
var charToMove = myMarkupText.paragraphs[-1].characters[-1];

// Move that character in:
charToMove.move
( 
	LocationOptions.AFTER , 
	myMarkupText.insertionPoints[-1] 
);

// Move the markup text at the end of the story:
myXMLElement.move
( 
	LocationOptions.AFTER , 
	myMarkupText.parentStory.texts[0] 
);

// Move the character out:
var indexOfCharToMove = myMarkupText.characters[-1].index;
myMarkupText.characters[-1].move
( 
	LocationOptions.AFTER , 
	myMarkupText.parentStory.characters[ indexOfCharToMove+1 ] 
);

 

To build a "industrial strength" function for generalized issues like this is a totally different thing. Just want to give an idea how one can handle this case.

 

Regards,
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
community guidelines
Explorer ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

LATEST

Hi @Laubender @Peter Kahrel 

my mistake

while integrating the script on server i have removed app.select , alert,app.activeDocument,app.cut,app.paste,$.bp(), etc. this i have used for debugging purpose only.

 

Thanks

Anupam

 

 

 

 

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
community guidelines