Skip to main content
Inspiring
December 24, 2018
Question

Parent of Link

  • December 24, 2018
  • 4 replies
  • 1192 views

Hi,

  

     When doing the image alignment, i have used to the below syntax to get the parent of the link and moving that object. For few images, its throwing an error. Because, parent of the link is returning as "Document".  I don't know the reason.

var PgItem = myPage.place(imgPath,[0,0],undefined,false,true,undefined);   

var parent = PgItem[0].parent;

Parent object is returning "Document" instead of "Rectangle".

This topic has been closed for replies.

4 replies

January 7, 2022

I had this same issue. Sometimes rect[0].parent code returns [object Rectange]  and [object Document]

rect[0].parent // return [object Rectange]  and [object Document]

 

And I could replicate this issue on a demo file (check attached)

I couldn't move the images around with document object. 

Please confirm if this is a bug? any workaround would be appreciated?

 

Community Expert
January 7, 2022

Seems some document corruption. I exported the file as IDML(download link here) and then the second image gives the result as Object Polygon. However i see in your document both the images are shown as embedded but IDML shows only the first image as embedded the one with problem is removed from the link panel. How was this element placed orginally on the dicument?

-Manan

-Manan
Community Expert
December 31, 2018

Hm. Can you see a difference if you do:

PgItem[0].parent.getElements()[0]

instead of simply:

PgItem[0].parent

Regards,
Uwe

Community Expert
December 31, 2018

Scratch my last reply.

If an oval was converted to a rectangle it could still be considered an oval:

var doc = app.documents.add(),

    obj = doc.ovals.add({geometricBounds : [0,0,100,100]}),

    objId = obj.id;

obj.convertShape(ConvertShapeOptions.CONVERT_TO_RECTANGLE);

alert([

    "App Version:" +

    app.version,

    "Rectangles: " +

        doc.rectangles.length,

    "Ovals: " +

        doc.ovals.length,

    "Current object: " +

        doc.pageItems.itemByID(objId).getElements()[0].constructor.name

    ].join('\r'));

Result:

Regards,
Uwe

Sudha_KAuthor
Inspiring
January 2, 2019

Hi,

     Thank you for your reply... Then in that document they may used oval. Don't know about "Document".  If i face that issue in upcoming, i will post that.

     Thank you so much...

Community Expert
December 24, 2018

Hi Sudha,

strange.

Just tried your code with InDesign CC 2019 and the returned object for parent is [object Rectangle].

What's your version of InDesign?

To test your case and before running the script I placed an image so I could easily readout the link's filePath information to place the image again:

var myPage = app.documents[0].pages[0];

var file = File( app.documents[0].links[0].filePath );

var PgItem = myPage.place( file ,[0,0],undefined,false,true,undefined);

PgItem[0].parent // returns [object Rectangle]

Regards,
Uwe

Sudha_KAuthor
Inspiring
December 29, 2018

Hi,

     Sorry for the late reply...

     For one image is does not return "rectangle". So I have saved as the image and used to place.  After that its return correctly.  I don't know issue.

     Actual parent of the link is rectangle is it right?? but for few images when i try its returned "Oval".

Community Expert
December 29, 2018

Hm. I thought you said that [object Document] was returned?!

In the cases when [object Oval] was returned, did you place the image on the page or did you place it to a graphic frame?

Regards,
Uwe

Sunil Yadav
Legend
December 24, 2018

Can you share more information about your images or document or some screenshot to understand more clearly your challange.