Skip to main content
Participating Frequently
April 20, 2023
Question

Placing icml and get reference

  • April 20, 2023
  • 2 replies
  • 544 views

Im placing an ICML file in script and then unlinking the file.

 

I would like to manipulate the content of the  placedItem after insert, but placedItem is always undefined.

 

var fileToPlace = File.openDialog("Select ICML file to place", "*.icml");

var placedItem = app.activeDocument.place(fileToPlace);

app.activeDocument.links.itemByName(fileToPlace.name).unlink();

How do i manage to place content and then get an reference of the placed

This topic has been closed for replies.

2 replies

Peter Kahrel
Community Expert
Community Expert
April 21, 2023

app.activeDocument.place(fileToPlace)

 

This simply loads the place gun. As Robert said, you need to place the file somewhere. Be aware that place() returns an array of placed objects, even if you place just one item. So your code goes more or less like this:

var frame = // Some reference to a text frame
var fileToPlace = File.openDialog("Select ICML file to place", "*.icml");
var placedItem = frame.place(fileToPlace)[0];
// To embed the link, simply use itemLink: more efficient
placedItem.itemLink.unlink();

// placedItem is now a valid reference to the placed story

 

P.

Participating Frequently
April 21, 2023

Ok, I guess thats the issue. Were normally placing the files directly on page with CTRL-D and then drags/resizing the content to fill out the desired space. Our files contains all formats (coloums, span, fonts, styles), so placing content within a new textframe will reset that.

Robert at ID-Tasker
Legend
April 21, 2023

If you have reference to your destination - you can use it with place() - @Peter Kahrel already gave you an example - 1st line. 

 

Robert at ID-Tasker
Legend
April 20, 2023

placedItem should be your reference - but I think it's a link - so if in the next line you're unlinking it - you are destroying it? 

 

So you either need to place your file into a TextFrame first - or get a reference to the parent BEFORE you unlink. 

 

Update:

You are not destroying the link directly - but every operation on the link - destroys it automatically and creates new one in the background - that's why you need to get a reference to the parent BEFORE you modify the link.