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

Converting text to outline and then select it with javascript

Explorer ,
Jul 21, 2020 Jul 21, 2020

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!

TOPICS
Scripting
745
Translate
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 23, 2020 Jul 23, 2020

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(myD
...
Translate
Explorer ,
Jul 21, 2020 Jul 21, 2020
    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]] );
Translate
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 ,
Jul 21, 2020 Jul 21, 2020

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. 

Translate
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 22, 2020 Jul 22, 2020

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.

 

 

Translate
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 22, 2020 Jul 22, 2020

No go here... Not that these things did clean my code, but they didn't fix the code..

Translate
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 ,
Jul 22, 2020 Jul 22, 2020

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

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

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...

Translate
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
Participant ,
Jul 22, 2020 Jul 22, 2020

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!

 

 

Translate
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 22, 2020 Jul 22, 2020

Let me try that as well.

Translate
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 22, 2020 Jul 22, 2020

No go...

Translate
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
New Here ,
Apr 19, 2022 Apr 19, 2022
LATEST

if you can please help me convert jscript below to vsbscript. thank you so much

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

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();
            }

 

Translate
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