Highlighted

Converting text to outline and then select it with javascript

Explorer ,
Jul 21, 2020

Copy link to clipboard

Copied

So I was working on doing something in InDesign, and finally finished. The script works perfect, until its run on an Mac...

 

I am converting text to an outline, selecting everything on the page, and croping the page to fit the existing items on the page.

 

I believe the issue is that when run on a mac, the text converted to outline is no longer being seen as an item?


So, with that being said!!! Is there a way to convert a textFrame to an Outline and immediately have that conversion selected?

I will post my previous code in a reply in case that helps clarify.

Thanks in advance!

So I've got it...

 

For some odd reason it was not selecting all on a mac. And on one layer the item I needed was at [0], on the other it was [1].

 

So since I know the the outlined text is always the lowest item, I did this.

            //Clear selection
            app.activeDocument.select(NothingEnum.NOTHING);
            //Select text for bounderies
            if(myDocument.layers[0].name == "1 LINE"){
                currentPage.pageItems.item(0).select();
            }
            else if(myDocument.layers[0].name == "2 LINE"){
                currentPage.pageItems.item(1).select();
            }
            else{
                alert("Document improperly formatted.");
                exit();
            }

 

TOPICS
Scripting

Views

99

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

Converting text to outline and then select it with javascript

Explorer ,
Jul 21, 2020

Copy link to clipboard

Copied

So I was working on doing something in InDesign, and finally finished. The script works perfect, until its run on an Mac...

 

I am converting text to an outline, selecting everything on the page, and croping the page to fit the existing items on the page.

 

I believe the issue is that when run on a mac, the text converted to outline is no longer being seen as an item?


So, with that being said!!! Is there a way to convert a textFrame to an Outline and immediately have that conversion selected?

I will post my previous code in a reply in case that helps clarify.

Thanks in advance!

So I've got it...

 

For some odd reason it was not selecting all on a mac. And on one layer the item I needed was at [0], on the other it was [1].

 

So since I know the the outlined text is always the lowest item, I did this.

            //Clear selection
            app.activeDocument.select(NothingEnum.NOTHING);
            //Select text for bounderies
            if(myDocument.layers[0].name == "1 LINE"){
                currentPage.pageItems.item(0).select();
            }
            else if(myDocument.layers[0].name == "2 LINE"){
                currentPage.pageItems.item(1).select();
            }
            else{
                alert("Document improperly formatted.");
                exit();
            }

 

TOPICS
Scripting

Views

100

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
Jul 21, 2020 0
Explorer ,
Jul 21, 2020

Copy link to clipboard

Copied

    var myDocument = app.activeDocument;

    //Set current page
    var currentPage = myDocument.pages[0];
        
    //Create outlines of text
    currentPage.textFrames.everyItem().createOutlines();

    //Select items on current page
    for (var j=0; j<currentPage.pageItems.length; j++)
    {
         currentPage.pageItems.everyItem().select();
    }
    //Get outer bounds of selection for resize
    var gb = app.activeDocument.selection[0].geometricBounds;
    //Resize
    currentPage.resize(CoordinateSpaces.INNER_COORDINATES,
       AnchorPoint.TOP_LEFT_ANCHOR,
       ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
       [2000, gb[2]] );

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...
Jul 21, 2020 0
Adobe Community Professional ,
Jul 21, 2020

Copy link to clipboard

Copied

Not sure it would necessarily be a problem with Mac. Something different about the document perhaps (a different measurement setting)? If so, using [2000, gb[2]] may be causing an out of bounds exception. 

 

Best way to check is to wrap the whole codeblock in a try/catch statement, and alert the error on the catch: 

try {    
    var myDocument = app.activeDocument;

    //Set current page
    var currentPage = myDocument.pages[0];
        
    //Create outlines of text
    currentPage.textFrames.everyItem().createOutlines();

    //Select items on current page
    for (var j=0; j<currentPage.pageItems.length; j++)
    {
         currentPage.pageItems.everyItem().select();
    }
    //Get outer bounds of selection for resize
    var gb = app.activeDocument.selection[0].geometricBounds;
    //Resize
    currentPage.resize(CoordinateSpaces.INNER_COORDINATES,
       AnchorPoint.TOP_LEFT_ANCHOR,
       ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
       [2000, gb[2]] );
} catch(e) {
   alert(e + " on line " + e.line);
}

 

Other potential error in the code I see is:

 

for (var j=0; j<currentPage.pageItems.length; j++)
{
   currentPage.pageItems.everyItem().select();
}

 

You don't need the for loop; everyItem().select() should select every item in one fell swoop. 

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...
Jul 21, 2020 0
Explorer ,
Jul 22, 2020

Copy link to clipboard

Copied

Thanks for the crazy quick reply!

So it's the same exact document from one machine to the next.  It's weird!!

 

Ok, I made the changes and will test tomorrow when I've got a mac in front of me.  I'll update, but in the end the only real change being made is the looped select. Honestly, I had that doing something different previously and never removed the loop.  Either way, not sure that could effect it directly but then again it shouldn't be OS specific.

 

 

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...
Jul 22, 2020 0
Explorer ,
Jul 22, 2020

Copy link to clipboard

Copied

No go here... Not that these things did clean my code, but they didn't fix the 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...
Jul 22, 2020 0
Adobe Community Professional ,
Jul 22, 2020

Copy link to clipboard

Copied

Did you add a try/catch block around the code. Did you get an error alert if so?

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...
Jul 22, 2020 0
Explorer ,
Jul 23, 2020

Copy link to clipboard

Copied

I did. No error.  It just isn't selecting the converted outlines.  It's wierd because i will do it on one layer, but not the other...

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...
Jul 23, 2020 0
Participant ,
Jul 22, 2020

Copy link to clipboard

Copied

hi,
this line is error :

currentPage.textFrames.everyItem().createOutlines()

because textframe (maybe) enters the thread.

your way is make array and use loop, for example :

textframes = currentPage.textFrames.everyItem().getElements()
for(var i = 0; i < textframes.length; i++){
	try{textframes[i].createOutlines()}
	catch(e){}
}

and about resize ... 

you don't know what it is :

var gb = app.activeDocument.selection[0].geometricBounds

you should check the new page size to avoid any error.

good luck!

 

 

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...
Jul 22, 2020 0
Explorer ,
Jul 22, 2020

Copy link to clipboard

Copied

Let me try that as well.

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...
Jul 22, 2020 0
Explorer ,
Jul 22, 2020

Copy link to clipboard

Copied

No go...

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...
Jul 22, 2020 0
Explorer ,
Jul 23, 2020

Copy link to clipboard

Copied

So I've got it...

 

For some odd reason it was not selecting all on a mac. And on one layer the item I needed was at [0], on the other it was [1].

 

So since I know the the outlined text is always the lowest item, I did this.

            //Clear selection
            app.activeDocument.select(NothingEnum.NOTHING);
            //Select text for bounderies
            if(myDocument.layers[0].name == "1 LINE"){
                currentPage.pageItems.item(0).select();
            }
            else if(myDocument.layers[0].name == "2 LINE"){
                currentPage.pageItems.item(1).select();
            }
            else{
                alert("Document improperly formatted.");
                exit();
            }

 

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...
Jul 23, 2020 0