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

[Old topic] Find Text by Formatting and convert to outline

Community Beginner ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

Hi everyone!

I've found this script on an old topic and it's exactly what I need, however when I run it on JavaScript I get this message "found.createOutlines is not a function". Can anyone have a look on it for me?

var doc = app.activeDocument;


app.findTextPreferences = null;


app.findTextPreferences.appliedCharacterStyle = "Pink Text";


var found = doc.findText();


for(var i =0;i<found.length;i++)


{


        found.createOutlines();


    }


app.findTextPreferences = null;


Thanks in advance,
Rogerio

TOPICS
Scripting

Views

235

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 2 Correct answers

Advisor , Oct 26, 2022 Oct 26, 2022

Hello @Rogerio5C09,

 

Give this a try....

var doc = app.activeDocument;


app.findTextPreferences = null;


app.findTextPreferences.appliedCharacterStyle = "Pink Text";


var found = doc.findText();


for(var i =0;i<found.length;i++)


{


        found[i].createOutlines();


    }


app.findTextPreferences = null;

Regards,

Mike

Likes

Translate

Translate
Community Expert , Nov 18, 2022 Nov 18, 2022

Hi @Rogerio5C09,

This could also crash for other characters like whitespace characters etc. So one way to avoid the issue is to enclose the createOutlines method call in a try catch block so if the operation fails the code still moves ahead ignoring the error. Try the following code snippet

var doc = app.activeDocument;
if(doc.characterStyles.item("Pink Text") == null) {
	alert('Error!\n The Character Style "Pink Text" doesn'+"'"+'t exist. Create and apply the Character Style Pink Text and try a
...

Likes

Translate

Translate
Community Expert ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

Never outline Text in InDesign.

 

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
Advisor ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

Hello @Rogerio5C09,

 

Give this a try....

var doc = app.activeDocument;


app.findTextPreferences = null;


app.findTextPreferences.appliedCharacterStyle = "Pink Text";


var found = doc.findText();


for(var i =0;i<found.length;i++)


{


        found[i].createOutlines();


    }


app.findTextPreferences = null;

Regards,

Mike

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
Community Beginner ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

It worked! Thank you so much Mike! 🙂

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
Community Beginner ,
Oct 28, 2022 Oct 28, 2022

Copy link to clipboard

Copied

Hi Mike,

I would like to include an alert in case there isn't a Character Style called 'Pink Text" in the document. I have tried to do it myself, but no luck 😞  Could you please have a look?

var myCharacterStyleName = "'Pink Text'"; 

if (to be completed) {
	alert("Create a Character Style called " + myCharacterStyleName, "Outline Pink Text" , true);
    }

var doc = app.activeDocument;

app.findTextPreferences = null;

app.findTextPreferences.appliedCharacterStyle = "Pink Text";

var found = doc.findText();

for(var i =0;i<found.length;i++)

{

        found[i].createOutlines();

    }

app.findTextPreferences = null;


Thanks in advance,
Rogerio

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
Advisor ,
Oct 28, 2022 Oct 28, 2022

Copy link to clipboard

Copied

@Rogerio5C09,

 

Give this a try...

var doc = app.activeDocument;

if(doc.characterStyles.item("Pink Text") == null) {
alert('Error!\n The Character Style "Pink Text" doesn'+"'"+'t exist. Create and apply the Character Style Pink Text and try again.');
exit();
}


app.findTextPreferences = null;

app.findTextPreferences.appliedCharacterStyle = "Pink Text";

var found = doc.findText();

for(var i =0;i<found.length;i++)

{

        found[i].createOutlines();

    }

app.findTextPreferences = null;

Regards,

Mike

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
Community Beginner ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

Hi Mike,

Thanks for that! 🙂

I also need a version that keeps the editable formatted text in the document (right after the outline one). I created a hidden condition for the same. So, the script find the text by formatting (as usual), 1) duplicate each (right after in the same line); 2) outline the original formatted text; 3) find all the duplications by formatting and apply hidden condition 'Editable Text', so that only the outline text is visible in the document. Would that be possible?

Thanks,
Rogerio

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
Community Beginner ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

Hi @mikeb41294032 ,

I hope you're doing well 🙂

I have learned that if the Character Style is applied to only a paragraph mark (without any text along with), the script fails - see screenshots. Can we also create an alert for that? You can write "Please select one or more characters that can be converted to outlines and try again."

Capture1.PNG

Capture2.PNG
Thanks in advance,
Rogerio

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
Community Expert ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

LATEST

Hi @Rogerio5C09,

This could also crash for other characters like whitespace characters etc. So one way to avoid the issue is to enclose the createOutlines method call in a try catch block so if the operation fails the code still moves ahead ignoring the error. Try the following code snippet

var doc = app.activeDocument;
if(doc.characterStyles.item("Pink Text") == null) {
	alert('Error!\n The Character Style "Pink Text" doesn'+"'"+'t exist. Create and apply the Character Style Pink Text and try again.');
	exit();
}


app.findTextPreferences = null;
app.findTextPreferences.appliedCharacterStyle = "Pink Text";
var found = doc.findText();

for(var i =0;i<found.length;i++)
{
	try{
		found[i].createOutlines();
	}catch(e){}
}
app.findTextPreferences = null;

-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
Community Expert ,
Oct 29, 2022 Oct 29, 2022

Copy link to clipboard

Copied

Just a note:

The ExtendScript code you copied over was damaged when the thread was moved from the old InDesign Scripting Forum to this new one in October 2019. Iterator [i] was dropped in the code. A typical error by the merging process of the forum threads back then. Thankfully Mike @mikeb41294032 already posted the repaired code over there:

https://community.adobe.com/t5/indesign-discussions/find-text-by-formatting-and-convert-to-outline/m...

 

Thanks,
Uwe Laubender
( Adobe Community Expert )

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