7 Replies Latest reply on Mar 29, 2011 9:36 PM by dylw

    Big Problem getting Page Number of Images placed in Document

    codeworxx

      Hey Guys,

       

      we have a big problem getting the page number of placed images.

       

      Background:

      We need a Script which exports an XML File with some document information containing "Total Number of Pages", "Document Name", "all placed Images with Path and PAGE NUMBER where it is placed".

       

      All works fine except getting the Page Number. Here is our code:

       

      function main(){
          if(app.documents.length==0){
             return false;
          }
      
          var myDoc = app.documents[0];
          if (!myDoc.saved)
          {
              alert("Fehler.\rDas Dokument muß erst gesichert werden.");
              return false;
          }
      
          var createXMLDoc = confirm("Verwendungen"+"\r"+"Sollen Verwendungen exportiert werden?");
          if(!createXMLDoc)
          {
                  alert("cancel");
                  return false;
          }
          var myDocName = myDoc.name.split(".indd")[0],
                  myTXT_File = myDocName + '.xml',
                  myPath = myDoc.filePath + "/",
                  myCreator = "ttxt",
                  myType = "TEXT",
                  lks = myDoc.links,
                  lk,
                  totalLinks = lks.length,
                  totalPages = myDoc.pages.length,
                  linkFolder,
                  lkPath,
                  lkPage,
                  lkArray=[],
                  XMLLink,
                  xmContentBefore,
                  xmContentAfter,
                  f;
      
          for (myCounter = 0; myCounter<totalLinks;myCounter++ ) { 
               lk=lks[myCounter];
               alert(lk);
               lkPath = File(lk.filePath).parent.fsName;
               lkPage = getPageByObject(lk).name;
               alert(lkPage);
               XMLLink="\t\t<file>\r\
                \t\t\t<name>"+lk.name + "</name>\r\
                \t\t\t<path>"+lkPath+"</path>\r\
                \t\t\t<pagenumber>"+lkPage+"</pagenumber>\r\
                \t\t</file>\r";
               lkArray.push(XMLLink);
          } 
      
          xmContentBefore = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\r\
                                      <document>"+"\r\
                                      \t<information>\r\
                                      \t\t<docname>"+myDoc.name+"</docname>\r\
                                      \t\t<path>"+myDoc.fullName+"</path>\r\
                                      \t\t<links>"+totalLinks+"</links>\r\
                                      \t\t<pages>"+totalPages+"</pages>\r\
                                      \t</information>\r\
                                      \t<files>";
      
           xmContentAfter = "\t</files>\r\
                                      </document>";
          f = new File( myPath + myTXT_File ); 
          f.open( 'w', myType, myCreator ); 
          f.write( [xmContentBefore,lkArray.join("\r"),xmContentAfter].join("\r") ); 
          f.close();
          f.execute();
          alert("Dokument wurde erstellt!"+"\r"+"Export der Links beendet.");
      }
      main();
      
      function getPageByObject (myParent){ 
          alert(myParent.constructor.name);
           switch(myParent.constructor.name){ 
                case "Page": 
                     myParentName = myParent; 
                     break; 
                case "Spread": 
                     myParentName = "Pasteboard"; 
                     break; 
                case "Application": 
                     myParentName = ""; 
                     break; 
                case "Character": 
                     getPageByObject(myParent.parentTextFrames[0]); 
                     break; 
                default: 
                     getPageByObject(myParent.parent); 
                     break; 
           } 
           return myParentName; 
      }
      


      Has anyone any ideas??

       

      Thanks a lot.

       

      Sascha