Get selected textframe and apply underline to it.

Participant ,
Dec 09, 2020

Copy link to clipboard

Copied

I'm trying to underline the selected textbox with multiples properties. I have tried this below but it doesn't work. When I search the DOM I find underline in multiple places, Paragraph, ChangeTextPreferences, story... How do you know which one to go to for something like this.  Will the DOM ever make sense.  Thank you for any insight.

 

 

app.selection[0].paragraphs.item(0).ChangeTextPreferences = {
        underline: true,
        underlineColor: col,
        underlineOffSet: -2,
        UnderlineWeight: mySel
}

 

 

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

The Paragraph object does not have access to the changeTextPreferences property. This is in an application-level property that influences Replace Text operations (ie, what you can manipulate in the find/replace window of InDesign). Once setting these properties, you can call changeText() on certain DOM objects (ie Document or Story), to execute those find/replace operations. For instance: 

 

app.findTextPreferences.findWhat = "Hello";
app.changeTextPreferences.changeTo = "World";
app.changeTextPreferences.underline = true;
app.documents[0].changeText(); //changes all instances of Hello to World in a document, and underline them

 

Back to your question, the Paragraph object does have acess to the underline property, as you note. So,  in your example: 

 

app.selection[0].paragraphs.item(0).underline = true;

 

would underline the first paragraph in a selected text frame. If you wanted to do that to *every* paragraph in the text frame, you could do: 

 

app.selection[0].paragraphs.everyItem().underline = true;

 

since as you astutely note, Text Frame itself does not have access to the underline property. 

An alternative would be to apply underline to the Texts collection, which is available to TextFrame as a property: 

 

app.selection[0].texts.everyItem().underline = true;

 

Or the Characters collection, also available to TextFrame as a property: 

 

app.selection[0].characters.everyItem().underline = true;

 

 

TOPICS
Scripting

Views

90

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

Get selected textframe and apply underline to it.

Participant ,
Dec 09, 2020

Copy link to clipboard

Copied

I'm trying to underline the selected textbox with multiples properties. I have tried this below but it doesn't work. When I search the DOM I find underline in multiple places, Paragraph, ChangeTextPreferences, story... How do you know which one to go to for something like this.  Will the DOM ever make sense.  Thank you for any insight.

 

 

app.selection[0].paragraphs.item(0).ChangeTextPreferences = {
        underline: true,
        underlineColor: col,
        underlineOffSet: -2,
        UnderlineWeight: mySel
}

 

 

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

The Paragraph object does not have access to the changeTextPreferences property. This is in an application-level property that influences Replace Text operations (ie, what you can manipulate in the find/replace window of InDesign). Once setting these properties, you can call changeText() on certain DOM objects (ie Document or Story), to execute those find/replace operations. For instance: 

 

app.findTextPreferences.findWhat = "Hello";
app.changeTextPreferences.changeTo = "World";
app.changeTextPreferences.underline = true;
app.documents[0].changeText(); //changes all instances of Hello to World in a document, and underline them

 

Back to your question, the Paragraph object does have acess to the underline property, as you note. So,  in your example: 

 

app.selection[0].paragraphs.item(0).underline = true;

 

would underline the first paragraph in a selected text frame. If you wanted to do that to *every* paragraph in the text frame, you could do: 

 

app.selection[0].paragraphs.everyItem().underline = true;

 

since as you astutely note, Text Frame itself does not have access to the underline property. 

An alternative would be to apply underline to the Texts collection, which is available to TextFrame as a property: 

 

app.selection[0].texts.everyItem().underline = true;

 

Or the Characters collection, also available to TextFrame as a property: 

 

app.selection[0].characters.everyItem().underline = true;

 

 

TOPICS
Scripting

Views

91

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
Dec 09, 2020 0
Adobe Community Professional ,
Dec 09, 2020

Copy link to clipboard

Copied

The Paragraph object does not have access to the changeTextPreferences property. This is in an application-level property that influences Replace Text operations (ie, what you can manipulate in the find/replace window of InDesign). Once setting these properties, you can call changeText() on certain DOM objects (ie Document or Story), to execute those find/replace operations. For instance: 

 

app.findTextPreferences.findWhat = "Hello";
app.changeTextPreferences.changeTo = "World";
app.changeTextPreferences.underline = true;
app.documents[0].changeText(); //changes all instances of Hello to World in a document, and underline them

 

Back to your question, the Paragraph object does have acess to the underline property, as you note. So,  in your example: 

 

app.selection[0].paragraphs.item(0).underline = true;

 

would underline the first paragraph in a selected text frame. If you wanted to do that to *every* paragraph in the text frame, you could do: 

 

app.selection[0].paragraphs.everyItem().underline = true;

 

since as you astutely note, Text Frame itself does not have access to the underline property. 

An alternative would be to apply underline to the Texts collection, which is available to TextFrame as a property: 

 

app.selection[0].texts.everyItem().underline = true;

 

Or the Characters collection, also available to TextFrame as a property: 

 

app.selection[0].characters.everyItem().underline = true;

 

 

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...
Dec 09, 2020 1
Participant ,
Dec 09, 2020

Copy link to clipboard

Copied

Such a good explanation, thank you. The only one I'm having issues with now is 

app.selection[0].texts.everyItem().underlineOffSet = -2pt;

 

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...
Dec 09, 2020 0
Adobe Community Professional ,
Dec 09, 2020

Copy link to clipboard

Copied

Review the Text DOM again. Is it underlineOffSet, or underlineOffset? Scripting is very literal, and changes in punctuation can make or break your code. 

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...
Dec 09, 2020 0
Participant ,
Dec 09, 2020

Copy link to clipboard

Copied

Of course that was it. If you have the time, no worries if you don't but how did you finally break through in understanding how to navigate the DOM? I find myself thinking, that makes no sense alot when I try to understand what comes before something or after something. 

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...
Dec 09, 2020 0
Adobe Community Professional ,
Dec 09, 2020

Copy link to clipboard

Copied

I've been at it 10+ years and it still doesn't make a whole lot of sense half the time.

 

Trickiest thing is understanding parent relationships. At the bottom of each DOM page on the link I linked to, you can see an "Object Of" list. That gives you a sense of what a given object could be the parent of. 

 

This graphic might help, or it might confuse you more: https://www.indesignjs.de/auflage2/wp-content/uploads/2015/04/InDesign_Skripting_Kurzreferenz.pdf?fb...

 

Also good to experiment with collections, ie textFrame.paragraphs.everyItem() vs. textFrame.paragraphs.item(0), which is nearly equivalent to tf.paragraphs[0], which is nearly equivalent to tf.paragraphs.firstItem(), and so on. 

 

I also came into it with a decent handle on JavaScript fundamentals. That will help a lot. 

 

Long story short: Prepare for lots of trial and error if you decide to go deep into Extendscript. 

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...
Dec 09, 2020 0