Copy link to clipboard
Copied
I'm new to the SDK.
I'm trying to have a plugin dispatch a custom event to a Javascript event handler with a property that is an object in the scripting DOM, like a Story.
I am a bit confused how to get there. The Custom Script Events section of the Programming Guide cites the example of a mutation event, though I can't find any example in the SDK where this actually used. I've defined the custom event in the .fr file, but I don't see how to attach the iTextModel to that event, and I imagine I need to create a proxy object for it, but I'm also unclear how to do that.
I can successfully call target->DispatchScriptEvent with my event and a callback handler, and my callback handler is properly invoked when the event fires. But how do I add a property to the event IScriptEvent *e which the callback is called with?
I spent a while barking up the wrong tree because the Programming Guide talks about optional parameters to Events and gives examples that don't work, but it really means Methods, I guess that's dated information from older version of the SDK.
Any suggestions? Thanks!
Copy link to clipboard
Copied
Haven't yet touched that area - too much scripting recently, but if you look at the SDK docs for IScriptEvent,you'll find boss classes that implement that interface. These events also have an IScript interface, so they are just other scriptable objects. Therefor you should be able to add fields via a matching IScriptProvider - plenty examples in the SDK.
Dirk
Copy link to clipboard
Copied
Yeah, well, you make it sound so simple. I think I'm stuck at the FR level.
I can declare my event in the VersionedScriptElementInfo no problem:
Event {
kPJEventTestScriptElement, //ScriptElementID
e_TestEvent, // ScriptID
"on test",
"Dispatched when a test happens.", //Description
kTrue, //Bubbles
kFalse, //Cancelable
kBaseScriptEventBoss, //ClassID of the Event object
c_Event // ScriptID of the Event object
}
which it turns out is sufficient to add it to the top-level Event object as Event.ON_TEST.
And then I have a Provider statement which makes it dispatch to registered javascript handlers:
Provider {
kPJScriptProviderBoss, // provider boss ID
{Object { kApplicationObjectScriptElement },
Event { kPJEventTestScriptElement }
}
}
I can easily add my test property to, say, every PageItem. But when I try to add it to every kPJEventTestScriptElement, it doesn't work: my Javascript handler throws an exception trying to read the property of the received event. E.g.
app.addEventListener(Event.ON_TEST, function(e)
{ $.writeln(e.propname); }
);
fails. This is how I'm trying to add the property to the Event:
Provider {
kPJScriptProviderBoss,
{
Object { kPJEventTestScriptElement }
Property { kPJEventPropertyScriptElement, kReadOnly }
}
}
but if I change kPJEventTestScriptElement to kPageItemObjectScriptElement, then evaluating app.activeDocument.pageItems.everyitem().propname works fine.
I can see there's a difference here -- with kPageItemObjectScriptElement it's hanging a property off an object that already exists. And in my case, I want to hang a property onto a TYPE of object that is created earlier in the resource spec. But I'm not sure how to do that. I played around with a bunch of syntaxes with RepresentObject and soforth, and didn't get anywhere.
I can't find any examples that do this sort of thing -- am I being dumb? There are not many examples with custom events -- just customscriptevents -- and the examples of adding properties seem all be adding them to existing objects in the DOM, not to a new object type...
Thanks again.
Copy link to clipboard
Copied
Just had a bit more time than the hurried previous reply.
You're right, Methods used to be named Event (probably from their AppleEvent heritage). The scripting glue interfaces have seen major renames and cleanups for every other version.
As you already found, in the scripting object model the new Event is a special type. With a plugin you can access the IScriptInfoManager and iterate most information matching the .fr resources. I've only right now extended my own reporting plugin to also cover the events, and searched the output for any reference. At least there the built-in events do not have matching object definitions. For an own Object definition (that will not neccessarily work for Event) search the examples for RepresentObject - e.g. BasicPersistInterface does it.
I'm afraid you're on your own with that problem, if others haven't figured it out maybe it is time to file a support request.
Dirk
Find more inspiration, events, and resources on the new Adobe Community
Explore Now