0

We're developing an InDesign CS6 Extension with Adobe Flash Builder 4.6. I got strange errors in a JavaScript Injection, so I converted the JavaScript to Action Script and put it directly into my code. But the errors continue to appear.

This is the code:

var pageItem:PageItem = (component as BaseComponent).pageItem;
var frame:Frame = new Frame(pageItem);
var itemIsHidden:Boolean = !pageItem.visible;
var tempFile:File;
var container:Rectangle = InDesign.app.activeDocument.rectangles.add(InDesign.app.activeDocument.activeLayer); // (2)

try {
    pageItem.visible = true;
    var prefix:String = "TMP_IMAGE_CONTAINER";
    var bounds:Array = frame.convertToBounds();

    Log.log("Container id = " + container.id);
    Log.log("bounds = " + bounds);
    Log.log("frame.ax = " + frame.ax + ", frame.ay = " + frame.ay);

    container.name = prefix+container.id; // (3)
    container.geometricBounds = bounds; // (1)
    container.strokeWeight = 0;
    container.strokeColor = InDesign.app.activeDocument.swatches.item("None");
    container.fillColor = InDesign.app.activeDocument.swatches.item("None");
    container.visible = true;
    container.transparencySettings.blendingSettings.opacity = 100;

    // create a duplicate of the pageItem in the tmp container
    var copyItem:PageItem = pageItem.duplicate(InDesign.app.activeDocument.activeLayer);
    copyItem.transparencySettings.blendingSettings.opacity = 100;
    copyItem.locked = false;
    container.geometricBounds = bounds;
    container.move([frame.ax,frame.ay]); // (4)
    copyItem.visible = true;

    InDesign.app.select(copyItem);
    InDesign.app.cut();
    InDesign.app.select(container);
    InDesign.app.pasteInto();

    //InDesign.app.scriptArgs.setValue("container", prefix+container.id);

    // [...]

} catch (e:Error) {
    Log.log(e.toString());
    Log.log(e.getStackTrace());
} finally {
    if (container) {
        container.remove();
    }
        pageItem.visible = !itemIsHidden;
}

The log statements at the beginning are to make sure, the variables are defined at this point. However, I get errors all the time in a (seemingly) random manner: (1)

[INFO] [29:1786:739] [ImageExporter::export():65] Container id = 12818
[INFO] [29:1787:386] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [29:1787:931] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [29:1799:462] [ImageExporter::export():113] Error: Invalid value for set property 'geometricBounds'. Expected Array of 4 Units, but received null.

or (2)

Error: Cannot create page item. No valid parent found.
    at flash.external::HostObject/__call()
    at com.adobe.csawlib::CSHostObject/hostCall()
    at com.adobe.indesign::Rectangles/add()
    at ImageExporter/export()[...export/ImageExporter.as:58]

or (3)

[INFO] [14:843:201] [ImageExporter::export():65] Container id = 12818
[INFO] [14:843:202] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [14:843:202] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [14:843:239] [ImageExporter::export():114] Error: Invalid value for set property 'name'. Expected String, but received null.

or (4)

[INFO] [17:1025:895] [ImageExporter::export():65] Container id = 12818
[INFO] [17:1025:896] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [17:1025:896] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [17:1025:964] [ImageExporter::export():115] Error: Missing required parameter 'to' for method 'move'.
    at flash.external::HostObject/__call()
    at com.adobe.csawlib::CSHostObject/hostCall()
    at com.adobe.indesign::Rectangle/move()
    at ImageExporter/export()[.../export/ImageExporter.as:83]

The errors appear always while exporting the same object. We checked the syntax inside our extension and the objects in InDesign, but everything seems to be fine.

I'm new to Action Script but my common sense as developer tells me, that (1) bounds is an array with 4 entries (as stated in the log message) and (2) even if there is no valid parent, the extension should have crashed here every time (I use the same document every time).

It could be a memory overflow error (because the errors only appear in InDesign-Files with many objects) but I couldn't find an option to increase it.

Note: The Rectangle used in this class is a class from the Extend script API.

Community
  • 1
  • 1
Florian Gössele
  • 4,376
  • 7
  • 25
  • 49
  • 2
    Well it seems like from time to time there are no bounds or smth like that. It's best to write if-else statements and log whenever there is something wrong. I cannot imagine InDesign has such bugs so from time to time there are errors :) Simply put `if (!value)` statements for each var.. – Andrey Popov May 19 '15 at 11:31
  • 2
    I wouldn't recommend using AS3 wrappers for so many reasons. First of all Adobe has dropped support for Flash Based Extensions. Second of all, using wrappers will limit porting your extension to html based extensions later. I will definitively keep on using pure extendscript script for whenever you need to interact with InDesign and AS3 to whatever deals with user interaction and interface. – Loic May 19 '15 at 15:04
  • I also remember that passing objects from AS3 to ExtendScript could have some hiccups. In some cases, I turned data to strings or xml strings and evaling those back in extendscript. Of course an array (bounds) is an array but you may deal with AS3 instantiated Arrays Objects vs ExtendScript instantiated Object Arrays which may lead to issues. Oh I remember something about this now… – Loic May 19 '15 at 15:07
  • 1
    Look at http://blogs.adobe.com/cssdk/category/cssdk/indesign-extensions and specially hostObjectDelegate ;) – Loic May 19 '15 at 15:18

0 Answers0