How to EXCLUDE MasterPage items when bulk exporting all text Frames

假如想象 提交于 2019-12-10 11:47:55

问题


When I'm exporting all text frames from a file, the script sees the textframes in the masterpage and messes up the calculation and gives an error at the end because those frames are locked and can't be exported.

var myDoc = app.activeDocument;
var myFolder = myDoc.filePath;
var myImage = myDoc.textFrames;

var JPEGFolder = new Folder(myFolder+"/"+app.activeDocument.name+"_"+"JPEG");
if (!JPEGFolder.exists)
        JPEGFolder.create();  

var PromFolder = new Folder(myFolder+"/"+app.activeDocument.name+"_"+"Promethean");
if (!PromFolder.exists)
PromFolder.create();

var ToplamSoru = 0 ;

for (var i=0; myImage.length>i; i++)
    {
            app.select(myImage[i]);
            ToplamSoru = ToplamSoru +1;
    }

var Cevapli = (ToplamSoru/2-4);
alert(Cevapli);

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.maximum;
app.jpegExportPreferences.exportResolution = 150;

for (var p=0; p < myDoc.pages.length; p++)
{
        for (var i=0; myImage.length>i; i++)
            {
                if ( i <= Cevapli -1){
                    if( i < 9)
                        {
                        app.select(myImage[i]);
                        var SoruNo  = myImage[i].contents.substring(1,2);
                        app.selection[0].exportFile(ExportFormat.JPG, File(JPEGFolder+"/"+SoruNo+".JPEG"), false);
                        }
                    else
                        {
                        app.select(myImage[i]);
                        var SoruNo  = myImage[i].contents.substring(1,3);
                        app.selection[0].exportFile(ExportFormat.JPG, File(JPEGFolder+"/"+SoruNo+".JPEG"), false);
                        }
                    }
                else{
                    //alert(Cevapli);
                    if( i < 9 + Cevapli+1) 
                        {
                        app.select(myImage[i]);
                        var SoruNo  = myImage[i].contents.substring(1,2);
                        app.selection[0].exportFile(ExportFormat.JPG, File(PromFolder+"/"+SoruNo+".JPEG"), false);
                        }
                    else
                        {
                        app.select(myImage[i]);
                        var SoruNo  = myImage[i].contents.substring(1,3);
                        app.selection[0].exportFile(ExportFormat.JPG, File(PromFolder+"/"+SoruNo+".JPEG"), false);
                        }
                    }

            }
        }
alert ("Done")

Basically, when i run the code, everything is OK and exported as wanted, but when there are more than the fixed number of text frames in the masterpage, it will be screwed up once again.

var Cevapli = (ToplamSoru/2-4);

Is where i decrease the value of the variable because there are 2 master pages with 4 different locked text frames.

How can i actually make the code exlude the items in the masterpages altogether?

The working code below:

var myDoc = app.activeDocument;
var myFolder = myDoc.filePath;
var TotalQuestions = 0 ;
var JPEGFolder = new Folder(myFolder+"/"+app.activeDocument.name+"_"+"JPEG");
var PromFolder = new Folder(myFolder+"/"+app.activeDocument.name+"_"+"Promethean");
var TotalPages = 0;
var Extension = prompt("Başına ne koyalım?","fen-");

if (!JPEGFolder.exists)
JPEGFolder.create();  

if (!PromFolder.exists)
PromFolder.create();

for (i=0; i< app.documents[0].pages.length; i++)
{
      TotalPages = TotalPages+1;
      for (ii=0; ii< app.documents[0].pages[i].textFrames.length; ii++)
      {
              app.select(app.documents[0].pages[i].textFrames[ii]);
              TotalQuestions = TotalQuestions +1;
        }
}
//alert(ToplamSoru);
var Cevapli = TotalPages/2;
//alert(Cevapli);

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.maximum;
app.jpegExportPreferences.exportResolution = 72;
var result = confirm ("Devam?", false,"EU Thingie");

    if(result ==true){
        for (i=0; i < app.documents[0].pages.length; i++){
            // CEVAPLI //
            if(i < Cevapli){
            //alert(i+" "+ii+" IF");
                for (ii=0; ii < app.documents[0].pages[i].textFrames.length; ii++){
                var QID  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,3);
                    if( QID < 10){
                        app.select(app.documents[0].pages[i].textFrames[ii]);
                        var Less  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,2);
                        app.selection[0].exportFile(ExportFormat.JPG, File(PromFolder+"/"+Extension+Less+".JPEG"), false);
                    }
                    else{
                        app.select(app.documents[0].pages[i].textFrames[ii]);
                        var More  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,3);
                        app.selection[0].exportFile(ExportFormat.JPG, File(PromFolder+"/"+Extension+More+".JPEG"), false)                        
                    }    
                }
            }
                // CEVAPSIZ //
            else{
                //alert(i+" "+ii+" ELSE");
                for (ii=0; ii < app.documents[0].pages[i].textFrames.length; ii++){
                    var QID  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,3);
                    if( QID < 10){
                        app.select(app.documents[0].pages[i].textFrames[ii]);
                        var Less  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,2);
                        app.selection[0].exportFile(ExportFormat.JPG, File(JPEGFolder+"/"+Extension+Less+".JPEG"), false);
                    }
                    else{
                        app.select(app.documents[0].pages[i].textFrames[ii]);
                        var More  = app.documents[0].pages[i].textFrames[ii].contents.substring(1,3);
                        app.selection[0].exportFile(ExportFormat.JPG, File(JPEGFolder+"/"+Extension+More+".JPEG"), false)   

                    }

                }
            }
        }
    }
//alert ("Done")

回答1:


This will loop through the pages and every textFrame on each page. The text frames from Master Pages will be ignored.

for (i=0; i< app.documents[0].pages.length; i++){

      for (ii=0; ii< app.documents[0].pages[i].textFrames.length; ii++){

              $.writeln(app.documents[0].pages[i].textFrames[ii].contents);
          }

    }


来源:https://stackoverflow.com/questions/54282432/how-to-exclude-masterpage-items-when-bulk-exporting-all-text-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!