我有以下场景。我必须将页面项目复制到新的Indesign文档中,然后比较所有属性,并将不相等的属性写入日志文件。
我使用以下代码:
var textFramesCollection = new Array();
var myDocHeight;
var myDocWidth;
main();
function main()
{
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
app.scriptPreferences.measurementUnit = MeasurementUnits.millimeters;
try
{
myDocHeight = app.activeDocument.documentPreferences.pageHeight;
myDocWidth = app.activeDocument.documentPreferences.pageWidth;
textFramesCollection = app.activeDocument.textFrames;
var newInddDoc = app.documents.add();
newInddDoc.documentPreferences.pageHeight = myDocHeight;
newInddDoc.documentPreferences.pageWidth = myDocWidth;
for( var j = 0; j < textFramesCollection.length; j++)
{
var myPageItem = newInddDoc.pages.item(0);
var newPageItem = textFramesCollection[j].duplicate(myPageItem) ;
comparePageItems( textFramesCollection[j], newPageItem);
}
//app.activeDocument.close(SaveOptions.NO);
}
catch(e)
{
alert(e);
}
}
function comparePageItems( pageItemOne, pageItemTwo)
{
try
{
var Log = checkTypeOfProperty (pageItemOne, pageItemTwo, "", false, "", 0);
logInfo(Log);// write in the log file
}
}
function checkTypeOfProperty(objOne, objTwo, path, isRecursive, strLog, level)
{
try
{
for (var property in objOne)
{
var propPath = property;
if (isRecursive)
{
propPath = path + "." + property;
}
try
{
if (typeof (objOne[property]) == 'object')
{
strLog = checkTypeOfProperty(objOne[property], objTwo[property], propPath, true, strLog);
}
else if (objOne[property] != objTwo[property])
{
strLog += typeof (objOne[property]) + " : " + propPath + " :: " + objOne[property]+ "n";
}
}
catch(e)
{
}
}
return strLog;
}
catch(e)
{
}
}
有没有其他方法可以做到这一点,因为这需要很多时间,因为房产的数量太多了。
我写了一个脚本,它采用现有的InDesign文档,并从中生成相应的JavaScript/JSX。它对文档进行了逆向工程,生成的JavaScript代码包含具有所有属性的对象。
您可以在文档中使用它,然后比较生成的JavaScript代码。
目前,只有最重要的对象是用它们的所有r/w属性生成的:
- 文档,文档首选项
- 颜色
- 层
- CharacterStyleGroups
- CharacterStyles
- 页码
- PageItems:矩形、椭圆、图形线、多边形、文本框
除了生成的JavaScript之外,还可以导出所有属性的注释。它无法导出的所有引用对象也会被注释掉,但至少你可以看到它们的类型。
脚本下载页面,包含描述和示例:gd_indd2jsx.jsxbin
描述是德语的,但你只需要一个活动的InDesign文档,例如一个TextFrame,然后运行脚本。这会在脚本旁边生成一个新文件,后缀为_GENERATED.jsx,并带有正确的缩进JavaScript代码。它还应用正确的枚举常数值,而不是它们的原始整数值。
我希望这能有所帮助。
ALex