Copy link to clipboard
Copied
I'm trying to find if there is a way to get position data from an object while it's being dragged / repositioned by the user, but I'm not finding a way to get values updated until after the drop has completed.
For context, I've tried events with AIHostAdapter as well as native events in the C++ SDK directly, but neither seem to have any events for dragging position updates, their events only seem to be before and after dragging objects, so I'm resorting to polling.
Currently I can poll an object's left/top position during dragging, however the results are the original position until the drag is completed, it's only updated after drop.
Have tried polling:
app.activeDocument.selection[0].left;
app.activeDocument.selection[0].top;
app.activeDocument.selection[0].geometricBounds[0];
app.activeDocument.selection[0].geometricBounds[1];
Copy link to clipboard
Copied
@Dirk Becker any ideas?
Copy link to clipboard
Copied
Sorry. My only Illustrator plug-in implements an own font+text scripting similar to InDesign's, and works around the worst ScriptUI oddities (that BridgeTalk thing). I have not even touched any kind of notifications beyond my menu item.
Copy link to clipboard
Copied
No worries Dirk, thanks for replying. 🙂
Copy link to clipboard
Copied
I am not familiar with it, so I can't help you. However, note that such a large number of property accesses in Illustrator's ExtendScript will cause “MRAP” error and Illustrator will freeze, so this is not a good direction to go on.
The “Annotator” in the Illustrator SDK may be close.
Copy link to clipboard
Copied
Thank you! I checked out the Annotator sample and while it has some promising features like real-time position updates for the mouse and objects with Mouse Drag events and such, it looks like this info is only available to the plugin if the user has your custom tool selected, not by using a default tool like the Selection tool.
Does that limitation sound correct or are you aware of any ways to get MouseDrag info on the built-in tools?
Copy link to clipboard
Copied
It depends on what you want to create, but it seems sufficient to me to get start and end positions, because often I combine many such events into one by debouncing them.
Copy link to clipboard
Copied
Yea I had attempted a debounce strategy with AITimerSuite, but the timer seems to also wait until the drag is completed to run again. Would you recommend something other than timers for debouncing?
Copy link to clipboard
Copied
Since it is sufficient to get the start and end coordinates, I consider it a legitimate behavior to get the coordinates only once after a drag.
Any information on why it is important for your tool to get the coordinates during a drag, what your users gain from it, etc. might be helpful hints.
Copy link to clipboard
Copied
For sure, the end goal is for the tool to be notified when an object snaps to a guide as the user is dragging it.
This can be accomplished by getting the guide coordinates and cross referencing with the object boundaries, but currently the task can't be comlpeted since the object coordinates won't update while the user is dragging an object in ExtendScript or C++ APIs from what I've found, the position / coordinates will only update before and after the object dragging.
Might not be possible, but that's what I'm after.
Copy link to clipboard
Copied
How about changing your approach? If you want to snap to the guide, your tool could do that directly, instead of requiring a user drag operation.
Copy link to clipboard
Copied
That would be simpler, but the goal here is to just for the tool to be notified when an object snaps to a guide during drag, not the action of moving a object to a guide itself.
Copy link to clipboard
Copied
In other words, you want to do a proof of concept, not to be designing features for the user, is that correct?
Copy link to clipboard
Copied
@sttk3 Not necessarily. Imagine for example that an object is deformed when it is snapped to a guide, but at no other time. Or perhaps a message could appear when a guide is within snapping distance. I think there are many possibilities.
Copy link to clipboard
Copied
Good point. Wanting to be notified when an object snaps to a guide is a step in the process, not a goal. That is why I assumed it was a proof of concept.
Copy link to clipboard
Copied
I feel that getting notified when an object snaps to a guide can literally be a goal (a sub-goal, obviously, but still a goal). I mean, some functionality just won't work without that notification. And I couldn't draw the conclusion that it was a proof of concept from that information. Sorry if I'm nitpicking 🙂
Copy link to clipboard
Copied
Anyway, if it is unclear what the user will get in the end, why not assume that it is impossible because the cost is too high? Even if it is technically possible to notify.
Copy link to clipboard
Copied
Yes I suspect Justin is evaluating the cost/feasibility in this thread. I doesn't seem promising. I'm disappointed that even the SDK can't do it.
Copy link to clipboard
Copied
You cannot represent his thoughts, because you are not Justin. It is better to wait for his reply.
Copy link to clipboard
Copied
You are right, thank you. In fact, I shouldn't have spoken at all, as this topic is well beyond my experience. However I am interested in the findings. I will now take your advice.
Copy link to clipboard
Copied
Is this a proof-of-concept? Basically yes, this functionality is one potential feature of a larger tool that we're researching to see what is possible and what isn't in the Illustrator SDK.
Copy link to clipboard
Copied
Then there is no more information to add. Sorry.
Copy link to clipboard
Copied
Perhaps I'm overlooking something about your request, but Illustrator's built-in Info panel does provide that live info while dragging objects (based on mouse cursor position).
Wouldn't that suit your purpose?
Copy link to clipboard
Copied
Yes the Info panel's X/Y/W/H values do update in realtime. Do you know of a way to access them via the API?
Copy link to clipboard
Copied
No, unfortunately I don't know that.