• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible to create an eventListener inside SVG that would run in Illustrator?

Engaged ,
Apr 30, 2023 Apr 30, 2023

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?

TOPICS
Scripting , SDK , Third party plugins , Tools

Views

272

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Apr 30, 2023 Apr 30, 2023

Copy link to clipboard

Copied

LATEST

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:

 

  1. The CEP panel subscribes to a selection change event on mounting lifecycle
  2. AIHostAdapter sends an event to the listener
  3. The CEP panel triggers the callback for the listener
  4. The listener function would probably need to check app.selection.length to determine if something was selected or unselected
  5. If there was a selection, CEP would call a JSX function that does something like returns the UUIDs of all selected items
  6. If the target pageItem is contained in this list, it would then call a JSX function to relabel it with the new width

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines