I’m trying to create my first UXP-based InDesign plugin and I have run into a snag trying to retrieve layer properties. I’ve reduced my code to be very basic to show the issue that I’m encountering.
TypeError: Cannot read properties of undefined (reading name)
If I change the code to
alert(app.activeDocument.layers.length);
It alerts a value of 7 as there are 7 layers in the test document. It sees the layers but I’m not able to retrieve the layer properties for any of the layers.
Does anyone have any idea what the problem could be?
I don’t know if I want to get my hopes up, yet. But I recently tried it and it worked ~ 80 % of the time. So it’s not production-ready, yet (especially since I couldn’t figure out a pattern on when it works, so it seems to also fall into this "weird side-effects of UXP interacting with ExtendScript stuff in asynchronous contexts). But there’s definitely some implementation.
I watched your YouTube video First Attempts with UXP Plugins in InDesign: Demo and Lessons Learned and found it really helpful. Thank you for posting it!