I have the following scenario. I have to copy a page item into a new Indesign document and then compare all the properties and write the ones that are not equal into a log file.
I'm using the following code:
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)
{
}
}
Is there any other way to do this since, this is taking a lot of time as the no of property are too much.