Definition and query of ItemRef objects.

Version :
17.12.2024, 12:52 Uhr

Definition and query of ItemRef objects.

Please note the difference between the address of an ItemRef object and its UID: The address is the position of the ItemRef object in the memory. You can obtain such an address (but not yet an UID) with item::alloc, gFrame already has one. The UID, on the other hand, is (together with some other data) located at the address and InDesign can derive the referenced object from this number.

static ItemRef alloc(ItemRef org = 0)

Reserve memory capacity for an InDesign® object. The created ItemRef is thereby not yet connected with an InDesign® object. With alloc created ItemRefs these must be deleted again using item::release.

Please note the difference between the address of an ItemRef object and its UID: The address is the position of the ItemRef object in the memory. You can obtain such an address (but not yet an UID) with item::alloc, gFrame already has one. The UID, on the other hand, is (together with some other data) located at the address and InDesign can derive the referenced object from this number.

Name Type Default Description
Return ItemRef   New created empty reference to an InDesign® object
org ItemRef 0 original

0 : create a new empty ItemRef object
otherwise : make a copy of org Only the reference values are duplicated, not the refered objects itself!
ItemRef	frameRef = item::alloc ();

org since version 1.3.4 (P/R 74)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static ItemRef assign(ItemRef dest, ItemRef src)

Copy on ItemRef to another. The value of src is copied into dest Of course, only the reference is copied here, not the referenced InDesign object itself.

Please note the difference between the address of an ItemRef object and its UID: The address is the position of the ItemRef object in the memory. You can obtain such an address (but not yet an UID) with item::alloc, gFrame already has one. The UID, on the other hand, is (together with some other data) located at the address and InDesign can derive the referenced object from this number.

Name Type Default Description
Return ItemRef   dest or 0 on error
dest ItemRef - destination
src ItemRef - original

Version 1.3.4 (P/R 74)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int define(
  ItemRef dest,
  ItemRef srcDB,
  int UID,
  int checkIfExists = 1)

Define a reference to a document object.

Please note the difference between the address of an ItemRef object and its UID: The address is the position of the ItemRef object in the memory. You can obtain such an address (but not yet an UID) with item::alloc. The UID, on the other hand, is (together with some other data) located at the address and InDesign can derive the referenced object from that information.

[since v4.3 R34250, 2. Feb 2024] If span[src]{dest} is equal to gDocument, the current document of the script is automatically adapted. In this case uid must have the value 1! Below you will find an example.

Name Type Default Description
Return int   0 or ErrorCode.
dest ItemRef - Destination reference
srcDB ItemRef - Enter any (but a valid) object of the document in which your target object is located, gFrame is a good idea for example.

0 : Try to determine the document via the script environment:
  1. Current frame (gFrame)
  2. Current textmodel
  3. Current document
uid int - New object id
checkIfExists int 1 Before defing the item, check whether an object with given UID exists.

1 : Yes, please check
0 : No, define anyway

Check a range of document UIDs.

int main ()
{
    int 		i;
    ItemRef		ref	= item::alloc ();
for (i = 200; i < 301; i++) { item::define (ref, gFrame, i); wlog ("", "# UID %d : %d, 0x%X'\n",   i,   item::exists (ref),   item::get_class (ref)); }
return 0; }

The UID 1 always points to the document. The examples creates an ItemRef to the document of the current frame an shows the documents name.

int main ()
{
    ItemRef		docRef	= item::alloc ();
    char		docName	[4000];
item::define (docRef, gFrame, 1); document::name (docName, docRef); showmessage (docName);
return 0; }

Adapt gDocument to the current front document.

int front_doc_changed ()
{
    ItemRef 		docRef = document::get_front ();
item::define (gDocument, docRef, 1); item::release (docRef);
return 0; }

v3.3 R2489, 06.06.2011 Parameter checkIfExists since v4.1.6 R26001, 1. Oct 2019

priint:comet InDesign® Plug-Ins, comet_pdf

defined
exists
get_class
comet.CDocument.getFrame

static int release(ItemRef itm)

The reserved memory of an object reference is again released. The target object of the reference remains unaffected by this action.

Name Type Default Description
itm ItemRef - Reference to be released
ItemRef	frameRef = item::alloc ();
:
item::release (frameRef);	


priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int fitframe(
  ItemRef ref,
  int refPoint = 0,
  float* width = 0,
  float* height = 0)

Fit the frame, in which a reference is displayed, to its contents. In the optional parameters width and height, the new size of the frame can be requested.

Name Type Default Description
Return int   0 or ErrorCode
ref ItemRef - Reference to a document frame
refPoint int kRefPointTopLeft Which corner of the origin frame should be pinned when scaling? Please note, that text frames are changed only in their height and that inline frames are always held at the bottom right corner.

kRefPointTopLeft
kRefPointTopCenter
kRefPointTopRight
kRefPointLeftCenter
kRefPointCenter
kRefPointRightCenter
kRefPointBottomLeft
kRefPointBottomCenter
kRefPointBottomRight

To fit frames to the contained image, use the frame::fit_image function with method 3.
width float* 0 New width of the frame, Return value
height float* 0 New height of the frame, Return value
#include "internal/types.h"
ItemRef         frame   = item::alloc ();
document::find_frame (frame, 1, 1, 3, 4);
if (!item::defined (frame)) { item::release (frame); showmessage ("Frame not found"); return 1; } item::fitframe (frame); item::release (frame);


priint:comet InDesign® Plug-Ins, comet_pdf

frame::fit
frame::fit_better
frame::fit_image
comet.CFrame.fit

static int defined(ItemRef ref)

Does the reference indicate a valid object?

ItemRefs can point to different objects like frames, tables, documents, ... . A call to defined only anwsers the question, whether the reference points to any object. You can not be sure, that is object is a frame, or a doc, or something else. Anyway, for the most reasons, htis information is enough. To check, whether the ref is a valid frame, table, ... , use one of the corresponding is_valid methods.

Name Type Default Description
Return int   != 0 the object is defined, == 0 no object
ref ItemRef - Reference to a document frame
ItemRef         frame   = item::alloc ();
document::find_frame (frame, 1, 1, 3, 4);
if (!frame::is_valid (frame)) { item::release (frame); showmessage ("Frame not found"); return 1; } item::fitframe (frame); item::release (frame);


priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

frame::is_valid
table::is_valid
bookmark::is_valid
document::is_valid
hyerlink::is_valid

static int getint(ItemRef ref)

UID of the reference. Information on UIDs can be found here.

Please note the difference between the address of an ItemRef object and its UID: The address is the position of the ItemRef object in the memory. You can obtain such an address (but not yet an UID) with item::alloc, gFrame already has one. The UID, on the other hand, is (together with some other data) located at the address and InDesign can derive the referenced object from this number.

Name Type Default Description
Return int   Value of the referenz
ref ItemRef - documet reference

Version 1.4 R334 (13. April 2007)

priint:comet InDesign® Plug-Ins, comet_pdf

comet.CFrame.getUID

static int exists(ItemRef ref)

Does the reference indicate an existing object?

ItemRefs can point to different objects like frames, tables, documents, ... . A call to defined only anwsers the question, whether the reference points to any object. You can not be sure, that is object is a frame, or a doc, or something else. Anyway, for the most reasons, htis information is enough. To check, whether the ref is a valid frame, table, ... , use one of the corresponding is_valid methods.

Name Type Default Description
Return int   0 : No
1 : Yes, the object exists
ref ItemRef - reference

Check a range of document UIDs.

int main ()
{
    int 		i;
    ItemRef		ref	= item::alloc ();
for (i = 200; i < 301; i++) { item::define (ref, gFrame, i); wlog ("", "# UID %d : %d, 0x%X'\n",   i,   item::exists (ref),   item::get_class (ref)); }
return 0; }

v3.3 R2489, 06.06.2011

priint:comet InDesign® Plug-Ins, comet_pdf

static int get_class(ItemRef ref)

Get the class of an existing document object. Here's a small collection of IDs and their names.
ClassID Name
0xe01 kDocBoss
0x501 kSpreadBoss
0x50f kPageBoss
0x1401 kMasterPagesBoss
0x302 kDocumentLayerBoss
0x301 kSpreadLayerBoss
0x201 kTextStoryBoss
0x2c0f kPageItemBoss
0x263 kMultiColumnItemBoss
0x227 kFrameItemBoss
0x2c10 kDrawablePageItemBoss
0x6201 kSplineItemBoss - the frames of the document.
0x1701 kImageBaseItem
0x1702 kImageItem
0x2501 kPlacedPDFItemBoss
0x660b kEPSTextItemBoss
0x6611 kDisplayListPageItemBoss
0x6601 kEPSItem
0x6602 kPICTItem
0x6603 kWMFItem
0x660f kDCSItemBoss
0x401 kGroupItemBoss - InDesign® groups
0xb320 kTOPSplineItemBoss - text on path
0x3301 kGuideItemBoss
0x262 kInlineBoss - inline frames
0xb318 kTOPFrameItemBoss
0x10001 kBookBoss
0x1354C kBookmarkBoss
0x13501 kHyperlinkBoss
0xb603 kTableItemBoss
0xb608 kTableModelBoss
0x8c42 kImportLinkBoss - Images
0x8c44 kBidirectionalLinkBoss - Linked text objects (InCopy)
0x145D8 kMultiStateObjectItemBoss - Multi state objects
0x1450C kPushButtonItemBoss - Pushbuttons
0x14509 kFormFieldContentItemBoss
0x1450A kFormFieldItemBoss
0x1450B kAppearanceFormItemBoss
0x1450D kCheckBoxItemBoss
0x1450E kRadioButtonItemBoss
0x1450F kTextFieldItemBoss
0x14510 kListBoxFieldItemBoss
0x14511 kComboBoxItemBoss
0x14512 kSignatureFieldItemBoss
0x10001 kBookBoss
0x1354C kBookmarkBoss
0x13501 kHyperlinkBoss
0xb603 kTableItemBoss
0xb608 kTableModelBoss

Name Type Default Description
Return int   Class ID of existing object or 0
ref ItemRef - reference

Check a range of document UIDs.

int main ()
{
    int 		i;
    ItemRef		ref	= item::alloc ();
for (i = 200; i < 301; i++) { item::define (ref, gFrame, i); wlog ("", "# UID %d : %d, 0x%X'\n",   i,   item::exists (ref),   item::get_class (ref)); }
return 0; }

v3.3 R2489, 06.06.2011

priint:comet InDesign® Plug-Ins, comet_pdf

Paul Seidel
17.12.2024, 12:52 Uhr
Plugin Version 1.0.10
frame
itemlist

Alphabetic index HTML hierarchy of classes or Java