Let’s say i have a rectangle, and the user changes it’s position/size in xd. is there a way my plugin will know about this change and handle stuff?
For panel plugins, the update
lifecycle hook gets triggered whenever the document changes (https://www.adobe.io/xd/uxp/develop/tutorials/quick-start-panel/#update-your-ui). Unfortunately, it doesn’t provide any details about what in the document has changed.
What you could do would be to, on every update
call, go through the document, “save” its state in a variable, and then compare the document with the stored “previous” state in the update
hook.
The thing is that update
should be as performant as possible (since, as you can imagine, if your plugin executes complex code on every little edit the user does, this can impact the performance).
All in all, we can therefore say that yes, it is possible, but it does have its limitations. What probably wouldn’t be a big problem is to monitor a limited, “pre-defined” set of layers for changes of specific properties, which should be relatively performant to compare. I don’t think it would be a good idea to compare every single “property” of the document on every update, though.
Also, keep in mind that updates to the document don’t necesserily mean that you can detect this change. E.g., if another plugin’s pluginData
field of a SceneNode
gets updated, this is an update that you can’t detect. Thus, there can also be “empty” updates.
I hope this helps (even though it’s probably not as easy as you might have been hoping for),
Best,
Pablo
thanks so much for the answer. is there a way not to allow the user to change the size of an element, but be able to move it in the artboard?
No; plugins cannot restrict the sizes of elements. You could have a command that fixes it up after the fact, but not while the element is being edited.