0

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.

y suri
  • 21
  • 5

1 Answers1

1

I wrote a script, that takes an existing InDesign-Document and generates the corresponding JavaScript/JSX out of it. It sort of reverse engineers the document and the resulting JavaScript code contains the objects with all its properties.

You can use it on your documents and afterwards compare the generated JavaScript code.

Currently only the most important objects are generated with all of their r/w properties:

  • Document, DocumentPreference
  • Colors,
  • Layers,
  • CharacterStyleGroups,
  • CharacterStyles,
  • Pages,
  • PageItems: Rectangles, Ovals, GraphicLines, Polygons, TextFrames

Beside the generated JavaScript, comments for all properties can be exported too. All referenced objects which it could not export, are also commented out, but at least you can see their type.

Script-Download page with description and example: gd_indd2jsx.jsxbin

The description is in german, but all you need is an active InDesign Document with e.g a TextFrame and run the script. This generates a new file beside the script with the suffix _GENERATED.jsx with correct, indented JavaScript code. It also applies the correct enumeration constant values instead of their raw integer values.

I hope this helps a bit.

ALex

agreif
  • 411
  • 2
  • 15
  • I just stumbled upon your script, which is great. While playing around with it, I noticed that the script is able to extract the enumeration names (not only the values, i.e. it can extract some info like `ArrowHead.NONE` instead of only `NONE`. We had a discussion about his recently over at the Adobe Forums and could not figure out how to do this in InDesign CS6. I ran your script in ID CS6 and it apparently does work somehow. Is there any chance that you could explain to me, how you extract the enumeration name (so the `ArrowHead` part of `ArrowHead.NONE`)? Thank you! – mdomino May 31 '17 at 14:22
  • I think you cannot extract the correct type with a script, you only get the ID. I did something completely different... my initial starting point is the official InDesig xml specification, that contains all functions, values and Enumerations. I parsed this xml and generated a new generator-jsx-script that knows about all internals. There is stored that the 'ArrowHead.NONE' has the ID 1852796517. So if the generator-jsx-script sees a 1852796517 in the ArrowHead context, then it prints 'ArrowHead.NONE' in the final jsx script. BTW the generator-jsx-script is 700 KB large :) – agreif Jun 02 '17 at 08:14
  • Ah, I see. Thank you for your explanation. I just realize now, how huge the script actually is. So this is basically like a hardcoded lookup list. I think I cannot really use this approach for my purposes unfortunately. Still, thanks for the great script! – mdomino Jun 02 '17 at 11:02
  • yes it is harcoded, not by hand, but by another automatism, that looked up all the possibilities in the xml. – agreif Jun 02 '17 at 11:35