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

Please improve my script

Guide ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

Hi,

I wrote script for finding text size lower than 6 pts, text leading lower than 3 pts, hyphenation and ligature On.

It is working fine but taking too much time to process (let say 64 pages totally in my document), is it any modification done to improve its speed?

mypoinsize();

myleading();

mylig();

myhypandlig()

function mypoinsize(){

var myFrame=app.activeDocument.textFrames.length

var flag2=0;

for(i=0;i<myFrame;i++){

for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){

var myCV=app.activeDocument.textFrames.item(i).paragraphs.item(j).pointSize;

var myCV1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().pointSize;

if(myCV<6 || myCV1<6)

{

flag2=1

}

}

}

if(flag2==1)

{

alert("ERROR: Document contain less than 6 point size text"+"\r\r");

}

else

{

alert("Document doesn't contain less than 6 point size text"+"\r\r");

}

}             

//leading

function myleading(){

var myFrame=app.activeDocument.textFrames.length

var flag3=0;

for(i=0;i<myFrame;i++){

for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){

var myCV=app.activeDocument.textFrames.item(i).paragraphs.item(j).leading;

var myCV1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().leading;

if(myCV<3 || myCV1<3)

{

flag3=1

}

}

}

if(flag3==1)

{

alert("ERROR: Document contain less than 3 point size leading"+"\r\r");

}

else

{

alert("Document doesn't contain less than 3 point size leading"+"\r\r");

}

}

//hyp and lig

function mylig(){

var myFrame=app.activeDocument.textFrames.length

var flag4=0;

for(i=0;i<myFrame;i++){

for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){

var myResult=app.activeDocument.textFrames.item(i).paragraphs.item(j).hyphenation;

var myResult1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().hyphenation;

if(myResult==true || myResult1==true)

{

flag4=1

}

}

}

if(flag4==1)

{

alert("ERROR: Document contain Hyphenation"+"\r\r");

}

else

{

alert("Document doesn't contain Hyphenation"+"\r\r");

}

}      

//hyp and lig

function myhypandlig(){

var myFrame=app.activeDocument.textFrames.length

var flag4=0;

for(i=0;i<myFrame;i++){

for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){

myResult=app.activeDocument.textFrames.item(i).paragraphs.item(j).ligatures;

var myResult1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().ligatures;

if(myResult==true || myResult1==true)

{

flag4=1

}

}

}

if(flag4==1)

{

alert("ERROR: Document contain Ligature "+"\r\r");

}

else

{

alert("Document doesn't contain Ligature"+"\r\r");

}

}   

Advance thanks,

Karthi

TOPICS
Scripting

Views

641

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

Advisor , Apr 11, 2016 Apr 11, 2016

Sorry, i'm tried and did not think things through. You cannot use findGrep() to search for text that is smaller than 6pt.

You could try something like:

doc.stories.everyItem().textStyleRanges.everyItem().pointSize

That would return a fairly large array with all the text sizes in your stories (tables, footnotes not included).

Then you can either iterate through it, or you can filter it, or just sort it and test for the first element.

Votes

Translate

Translate
Advisor ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

why not use findGrep()?

Votes

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
Guide ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

Vamitul


I tried the find option for ligature and hyphenation, but not sure how to find below 6 pt size texts and below 3 pt leading texts.

app.findGrepPreferences = app.changeGrepPreferences = null;    

var doc=app.activeDocument;

var Frame = doc.allPageItems;

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

{

  if(Frame instanceof TextFrame)

    {

      app.findGrepPreferences = app.changeGrepPreferences =NothingEnum.nothing;

      app.findGrepPreferences.findWhat = "\\S";

      app.findGrepPreferences.ligatures = true;    

      var found =  doc.findGrep();

                    if(found.length > 0)

                    {

                        alert("ERROR: Document contain Ligature")

                    }

                }

        }

app.findGrepPreferences = app.changeGrepPreferences = null;    

Votes

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 ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

yes, you are right.

Votes

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
Guide ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

But how can i use findGrep() for finding point size and leading, any suggestions?

Votes

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 ,
Apr 11, 2016 Apr 11, 2016

Copy link to clipboard

Copied

Sorry, i'm tried and did not think things through. You cannot use findGrep() to search for text that is smaller than 6pt.

You could try something like:

doc.stories.everyItem().textStyleRanges.everyItem().pointSize

That would return a fairly large array with all the text sizes in your stories (tables, footnotes not included).

Then you can either iterate through it, or you can filter it, or just sort it and test for the first element.

Votes

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
Guide ,
Apr 12, 2016 Apr 12, 2016

Copy link to clipboard

Copied

Hi Vamitul,

Thank you for the idea. It works:

mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements();

for (i=0; i<mytext.length; i++)

{

if (mytext.pointSize < 6)

{

    alert("Some text have below 6 pt size");

}

}

Votes

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 ,
Apr 12, 2016 Apr 12, 2016

Copy link to clipboard

Copied

You do realise that with that code, you will get an alert for each bit of text that is under 6 pt.

I'd rather do something like:

var mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().pointSize;

mytext.sort();

while (mytext[0]===undefined){ //for some reason, we do get undefined values in some cases

    mytext.shift();

}

if (mytext[0]<6){

    alert('Bla bla blah. Text below 6pt');

}

Votes

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
Guide ,
Apr 12, 2016 Apr 12, 2016

Copy link to clipboard

Copied

LATEST

Yes, you are correct. I used flag to avoid the repeating instance like below upto my little knowledge

mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements();

var flag=0;

for (i=0; i<mytext.length; i++)

{

if (mytext.pointSize < 6)

{

    flag=1

}

}

if(flag==1)

{

alert("ERROR: Document contain less than 6 point size text"+"\r\r");

}

else

{

alert("Document doesn't contain less than 6 point size text"+"\r\r");

}

but the mytext.sort(); is a learning for me, thanks


Votes

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