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

Links Page number

Contributor ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

Hi,

     I am getting links page number from indesign document.  i have used before the same below code to get page number .  it was working.

     Now its not working correctly.  When I used alert to check page number and links name its showing correctly but if i remove alert and check final output its not working correctly.  Returning wrong page number.  I checked using sleep but no changes in the output.

     I don't know the issue.

     Code:

     var inddFiles = []

     var myDoc = null;

     var commonErr = ""

     var sourceFolder = Folder.selectDialog();

     get_File(sourceFolder, inddFiles, '.indd'); 

     if(inddFiles.length == 0)

    {

        alert("InDesign Files Not Found!!! Please Check Input Folder!!!");

        exit();

    }

    for(var cF = 0 ; cF  < inddFiles.length ; cF ++ )

    {

        myDoc = null;    

        var allMasterPgs = "";

        linkNames = [], linkPgNos = [], docNames = [];

       

       

        var inddFile = File(inddFiles[cF]);

        inddName  = decodeURI(inddFile.name);

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

       

        try{

                myDoc = app.open(inddFile);               

                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

        }catch(e){

            commonErr += inddName+",Problem in Opening the File.\n";  

        }

        if(myDoc != null)

        {

           

            doUnlock(myDoc);

            getLnkDetails(myDoc);

            alert( linkNames.length + " -  " + linkPgNos.length + "\n linkNames "+  linkNames + "\nlinkPgNos" + linkPgNos)

           

         }

     }

function getLnkDetails(myDoc)

{   

    var links = myDoc.links;

    var docName = myDoc.name;

    var lnkName = "";

   

    for(var dlCnt = 0; dlCnt < links.length; dlCnt++)

    {

        cLink = links[dlCnt];

       

        try{

            cLink.show();

            var myImgLnk = app.selection[0];

            var rect = app.selection[0].parent;

           

            try{

                //lnkName = File(app.selection[0].parent.graphics[0].itemLink.filePath).name

                lnkName = decodeURI(app.selection[0].parent.graphics[0].itemLink.name)

            }catch(e){

                lnkName = "";  

            }

        }catch(e){}

       

        if(lnkName.length > 0)

        {

            $.sleep (2000);

            //lnkName = lnkName.replace("%20"," ","gi");

            var lnkPg = findPage(app.selection[0].parent);

            if(lnkPg != null)

            {            

                if(lnkPg.parent.constructor.name == "MasterSpread")

                {

                }else{

                    docNames.push(docName);

                    linkNames.push(lnkName);

                    linkPgNos.push(lnkPg.name);        

                   

                    alert("lnkName " + lnkName +"\nlnkPg.name" + lnkPg.name)

               }

            }else{

                //------ Issue on getting page number

                errImgs.push(lnkName);

                errReasons.push("Error in Getting Page Number");

            }

        }else{

            //------- issue on getting image name

//~             errImgs.push();

//~             errReasons.push();

        }

    }

   // alert("links "+ links.length + "\nlinkNames " + linkNames.length)

}

function get_File(dir,myfile_arr,extension)

{

    var f = Folder( dir ).getFiles();

   

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

    {

        if( f instanceof Folder )

        {

            get_File( f,myfile_arr,extension)

        }else

        {

            if(extension!=".*")

            {

                if( f.name.substr( -extension.length ) == extension )

                myfile_arr.push(f)

            }

            else

            {

                myfile_arr.push(f);

            }

        }  

    }//for

    return myfile_arr;

}//fun

function findPage(theObj)

{

    var thePage = theObj;

    if (thePage.hasOwnProperty("baseline"))

    {

        thePage = thePage.parentTextFrames[0];

    }

    while (thePage.constructor.name != "Page")

    {

        var whatIsIt = thePage.constructor.name;

       

        switch(whatIsIt){

        

         case "TextFrame":

                   thePage = thePage.parentPage;                   

                break;   

         case   "Rectangle":

                    thePage = thePage.parentPage;          

                    break;

         case   "Polygon":

                    thePage = thePage.parentPage;          

                    break;

         case "Cell":

                    thePage = thePage.parent.parent;

                    break;

         case "Character":

                    break;

               

           case "Story":

                thePage = thePage.parent.textContainers[0].parentPage;

                break;

           default :

         }      

        return thePage ;

    }

}

TOPICS
Scripting

Views

259

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
Contributor ,
Mar 20, 2018 Mar 20, 2018

Copy link to clipboard

Copied

LATEST

Sorry...

Its working... file issue....

When converting idml to indd.. its working....

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