#targetengine "myEngineName"
선언은 InDesign에서 전역 변수를 기억하는 데 사용된다는 것을 알고 있습니다. 여기에 대한 정보는 http://incom.org/post/89818입니다. 그런
InDesign CS5 Script : '# targetengine'이 (가) 제대로 작동하지 않는 이유는 무엇입니까?
Error Number: 30476
Error String: "if(imgs[i].itemLink != null)" could not be completed because the object no longer exists.
...이나 뭐 어쨌든 : 여전히 글로벌 변수 imgs
에 대한 오류를 발생시킵니다로 전역 변수를 기억하기
그러나이 여전히 충분하지 않았다. 그것은 내 코드의 특정 라인을 좋아하지 않으며, 글로벌 변수
imgs
이 어떻게 인스턴스화되었는지 잊고있는 것처럼 보입니다.
그래서 나는 try-catch 문을 구현, 변수
imgs
을 reinstatiated이
했다이 문제를 해결할 수 있지만이 가정처럼, 왜
#targetengine "myEngineName"
문제가 해결되지 않습니다 ... 캐치의 반복자를 감소 ? -
http://forums.adobe.com/thread/748419
편집 :
#target "InDesign" // this solves the "Error Number: 29446" problem
#targetengine "session" // this solves the "Error Number: 30476" problem
var imgs; // global variable for the #targetengine "session" to keep track of
var document = app.activeDocument;
var newFolder = createFolder(document); // if subdirectory images DNE, create this folder with the function below
saveAllImages(document, newFolder); // with the function below
alert("The file conversion is complete!\n\nAll black & white images have been copied to:\n" + newFolder +
"\.\n\nAll color images have been replaced with the new black & white images in the current InDesign document.");
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function createFolder(doc)
{
try
{
/*
* type-casting the filePath property (of type object) into a String type;
* must be a String type to concatenate with the subdirectory variable (also of type String)
*/
var docPath = String(doc.filePath);
var subdirectory = "/BLACK AND WHITE IMAGES";
}
catch(e)
{
alert(e.message + "\n - reload the script, and it should work.");
exit();
}
var imagesFolder = docPath + subdirectory; // concatenating the two variables
if(!Folder(imagesFolder).exists)
{
Folder(imagesFolder).create();
}
return imagesFolder; // for instantiation outside of this function
} // end of function createFolder
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function saveAllImages(doc, folder)
{
imgs = document.allGraphics; // this is a global variable, for the #targetengine "session" to keep track of
var fileName = "";
var img = "";
var imgType = "";
for(var i = 0; i < imgs.length; i++)
{
try
{
if(imgs[i].itemLink != null)
{
fileName = imgs[i].itemLink.name;
img = new File(folder + "/" + fileName); // each image instantiated here
imgType = imgs[i].imageTypeName; // image type is determined here (.tif, .jpg, .png, etc..)
//alert("The file \"" + fileName + "\"\n\tis a " + imgType + " file."); // Note: escape characters
/*
* array for image options, instantiated from the function below;
* options[0] is the "MAXIMUM" image quality property, &
* options[1] is the "GRAY" image conversion property;
*/
var options = convertToBlackAndWhite(imgType);
// each image exported to the new folder here, by file type
switch(imgType)
{
case "GIF":
alert("This script cannot convert and export the GIF file:\n\t" + fileName + " !"); // Note: escape characters
break;
case "Adobe PDF":
break;
case "EPS":
break;
case "Windows Bitmap":
break;
case "JPEG":
break;
case "PNG":
break;
case "TIFF":
options[0]; // maximum image quality
options[1]; // black & white conversion
imgs[i].exportFile(ExportFormat.JPG, img, false);
replaceWithNewImage(doc, fileName, img); // with the function below
break;
default:
alert("\tUnlisted image type: " + imgType + "!\nAdd this type to the switch statement.");
break;
} // end of switch statement
} // end of if statement
} // end of try statement
catch(e)
{
/*
* in case the #targetengine is overloaded, this solves the "Error Number: 30476" problem:
* - "The requested action could not be completed because the object no longer exists."
* (the second statement #targetengine "session" is also in place to solve this error)
*/
imgs = document.allGraphics; // global variable reinstantiated in case of error
i--; // retry the same iteration again, in case of error (the variable " i " is the iterator in the for loop)
}
} // end of for loop
} // end of function saveAllImages
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function convertToBlackAndWhite(fileType)
{
// array for image-quality and color-conversion values
var settings = [];
// each image exported to the new folder here, by file type
switch(fileType)
{
case "Windows Bitmap":
break;
case "JPEG":
break;
case "PNG":
break;
case "TIFF":
settings[0] = "app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM"; // maximum image quality
settings[1] = "app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY"; // black & white conversion
break;
default:
break;
} // end of switch statement
return settings; // for instantiation outside of this function
} // end of function convertToBlackAndWhite
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function replaceWithNewImage(doc, imageName, newImage)
{
var links = doc.links;
var link = "";
for(var i = 0; i < links.length; i++)
{
link = links[i];
if ((link.status == LinkStatus.NORMAL) && (link.name == imageName))
{
try
{
link.relink(newImage);
link.update();
}
catch(e)
{
}
} // end of if statement
} // end of for loop
} // end of function replaceWithNewImage
이 내가이 오류에 대한 찾을 수 밖에있는 유일한 정보는 : 여기
내 코드입니다 나는 그 문제가 확실히 있다고 확신한다. 함수 replaceWithNewImage
과 관련이 없으므로이 오류가이 함수없이 발생하지 않았으므로 try-catch 문이 필요하지 않습니다.
흥미 롭다. 그래서 대신 'app.activeDocument'를 사용하여'app.documents [0]'을 시도했는데, 이제이 오류는 *** 발생하지 않습니다. 그래서 변수가'app.activeDocument' 때문에 정의되지 않은 것처럼 보입니다. 그리고 이미지 폴더에 초점을 변경하는 문서가이 문제의 원인 일 수 있다고 가정합니다. @Loic 도움에 감사드립니다! –
글로벌 변수를 사용하지 않는 것이 좋습니다. – Loic