Copy link to clipboard
Copied
I was wondering if there was any way to create a shape in illustrator and then attach a script to that shape in the document.
I would like to have a text field inside of my SVG object that updates on resize. So I could create a simple event listener that looked like:
function onResizeEvent(e) {
let lbl=getLabel(e.target);
lbl.text(this.outerWidth+" px");
}
this is just pseudo-code to explain the idea.
even an embedded script like:
onUpdate=function (e) {
let elem=this;
let name=this.name.toProperCase();
let label=getLabel(this);
label.text(name);
};
Maybe even have a running script engine that would pass the events to a list of object.
Could someone write a plugin that would allow this to happen in Illustrator or is this entirely outside he realm of possibilities?
Copy link to clipboard
Copied
Generally anything that relies on user interactivity that isn't a hotkey or interaction with the script components itself (user interfaces like panels, buttons, ScriptUI dialogs, etc) is not possible. Scripting doesn't work like HTML with event handlers on art, it only works in that context for specific ScriptUI dialogs and their components like buttons, otherwise scripting isn't set up to do something automatically based on a user's action within a canvas.
What you've shown is entirely possible in HTML, and would probably be possible via CEP panel with use of AIHostAdapter. AIHostAdapter gives CEP panels certain events that it can subscribe to like onSelectionChange so the flow would be something like: