Skip navigation
Currently Being Moderated

How to save/retrive custom properties to a PageItem

Nov 28, 2011 2:16 AM

Tags: #cs5 #error #save #script #bug #javascript #properties #indesign #indesign_cs5.5 #indesign_cs5 #interactive #scripting #value #extendscript #question #pageitem #retrive

Hello community, have any of you succeeded in saving custom properties/data to a PageItem? I try to save my own properties to a PageItem using its property named properties. Setting properties seems to work but getting doesn't. This is my code (ActionScript 3.0):


var app:Application =;

var page:Page = app.activeDocument.pages.item(0);

var items:Array = page.allPageItems as Array;


// my properties

var myPropertyArray:Object = {fname:"John", lname:"Lennon"};


// set properties to first item of page

items[0].properties = myPropertyArray; // this works


// now get

var props:Object = items[0].properties; // Error: In wrapReturnedHostObject(), attempted invalid wrap: com.adobe.indesign::Enumerator returned as Object


I read on this forum that this is a bug of CSAWLib. If so, is there any other way to save my custom properties to an InDesign document?




  • Currently Being Moderated
    Nov 28, 2011 5:12 AM   in reply to Hoang_Huynh

    Hi Hoang,


    I'm afraid your code:


    items[0].properties = customObject;


    only *seems* to work, but actually does not. The properties property is a special command that only deals with native, valid, properties of a DOM object. Used as a setter, it simply ignores non-native keys. Used as a getter, it simply returns available properties. More generally, given a page item—say myRectangle— any statement such as myRectangle.myCustomProperty = "foobar" will cause an error ("Invalid property or method", or whatever) because you cannot extend DOM object instances. They all are command wrappers (=specifiers) and don't work as regular JS objects.


    Anyway, you can extend the methods of DOM object prototypes, e.g.:


    Rectangle.prototype.myCustomMethod = function(){ return this.label;};


    When you do that, keep in mind that a Rectangle object instance can reflect several actual InDesign rectangles. For example, myDoc.rectangles.everyItem() is seen as a Rectangle (in terms of cast).


    IMHO, the right way to attach custom properties to DOM components is to use insertLabel() / extractLabel() with serialized objects.





    EDIT: The CSAWLib bug you mention is not connected to the problem of setting custom properties.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points