Search code examples
javascriptadobe-indesignextendscriptadobe-extension

How to set default document effects using CEP/JavaScript?


I'm building an application which is drawing many objects (rectangles, lines, circle, etc.) in an Indesign document using CEP/JS. The issue I have is that all objects I’m adding are inheriting document’s default transparency settings, etc. which is a big issue as these settings are not under control (can be different on any document).

So, my first solution to this is to explicitly define all attributes for any object I’m drawing to overcome this and this works ok but the issue I have now is performance as I discover that settings all these objects attributes explicitly is taking a lot of time (and CPU). As a reference, I’ve to set around 40 attributes per object. On a test document with 100 objects to draw, it takes around 10 seconds and on the same document with exact same objects + settings 40 attributes, it goes to 40 seconds for the same job.

So question is :

  • Is it possible to prevent CEP to use the document default attribute when drawing new objects?
  • Is there a way to store the default values from the document in a variable, reset all the default values in the document prior to draw all my objects and then set the initial values back when done (to avoid having to set 40 attributes for every objects in a massive loop).

enter image description here


Solution

  • I applied @RobC and @Yuri Khristich's solution which is to use the ObjectStyle of type 'None' on the various items I draw. It still takes time but less than before.

    Here is the example :

    https://paste.ee/p/3fW9a

    var doc = app.activeDocument;
    
    // 1. Obtain a reference to the '[None]' Object Style.
    var noneObjectStyle = doc.objectStyles.itemByName('[None]');
    
    // 2. Draw a rectangle
    var rectangle = doc.pages[0].rectangles.add({
    geometricBounds: [0, 0, 50, 50],
    appliedObjectStyle: noneObjectStyle // <-- 3. Set its Object Style to [None].
      // ...
    });