I’m struggling just to get the coordinates of where the mouse clicked.
first of all: Welcome to the forums .
The short answer is: it’s impossible to do so.
The long answer: User interaction in the sense of the user clicking around in the document cannot get registered by plugins (or at least: not directly). For panel plugins, you can detect when something (e.g., the selection) has changed, but also not more than that.
The thing is that in order for a plugin for XD to do something, a user has to interact with the plugin’s UI in one way or another (call the plugin from the menu, do something in the panel, click “Ok” in a modal or something similar). If that does not happen, a plugin also isn’t allowed to make edits to the
scenegraph (I would imagine that if every plugin could just do stuff from the background at all times, this would have tremendous problems, especially with the new live collaboration).
Therefore, even if you were able to detect a mouse position, it wouldn’t really solve your problem. I would therefore suggest using some different strategy for your UX. One example (depending on your Use-Case, this may or may not work for you) would be to let the user draw a rectangle and then let the plugin “replace” this rectangle with whatever you want to place in the
scenegraph. Another way, depending on the use-case, would be to use the center of the screen (not a good solution, but depending on the use-case, this might also work). In this case, you might want to have a look at the
I hope this helps (although I can imagine it’s not the answer you were hoping for ),
Hi, @pklaschka, thank you for the informative reply! I’ll take a look into the drawing / replacing a rectangle trick.
@chriswingler Can you go into more context about what you’re trying to accomplish here – might be able to give some other options based on that information.