I'm trying to write an eventListener script to detect when an InDesign user places an asset from a library. It will then re-align other objects on the page to the newly placed objects.
My idea was to attach the eventListener to menuActions.itemByName("Place Item(s)") and do the adjustments afterInvoke. I'm stuck now on the possibility that the user will have more than one open library and more than one asset selected. The library assets that need this special treatment all have unique Descriptions, so I know that I can sort thru all the selected assets to look for a particular Description. But I've learned that it's always a good idea to check here first.
Even being able to detect the name of the Library Panel from which PlaceItems(s) was invoked would be a big help.
I have done a similar thing in the past, and used 2 methods. Both work, but may be concidered hacks!
1) Pass all page items ID's into an array before placing the Library item. Repeat after the item is placed, then comparing the 2 arrays you will get the item ID of the new placed item.
2) If you are able to, add a script label to the library item before placing it in the library. This way, after placing it, iterate through all page items until you find the page item with the label.
Both these ways feel clumsy to me, but do work. If anyone does have another, more efficient way, I would be interested to hear it too!
Is there any other simple solution? Please advice.