Copy link to clipboard
Copied
I am in process of creating an extension where I need to show thumbnails of all the artboards and layers.
Additionaly I want to update the thumbnails on every action user performs on artboard. ( just the way in standard layers dialog ).
As of now, I am using imagecapture() API to get the images of artboards and layers. Please suggest if there is any faster and easier way to achieve this.
Any help is highly appriciated.
Probably, DOCUMENT_CHANGED event fired when activeDocument switched.
However, I found below in ai_hostadapter helper script.
/**
* Sent when either a change in the selected art objects occurs or an artwork modification such as moving a point on a path occurs. You cannot distinguish a selection change from an artwork modification change. There is no notifier than means just one or the other. Receiving this does not necessarily mean that the set of selected objects, as returned AIMatchingArtSuite::
...Copy link to clipboard
Copied
that might be your only option, I can't think of anything else.
Copy link to clipboard
Copied
Perhaps this technique will be useful to you..
This method only works when the user activates extension:
Create a <input type="hidden" id="isActiveExt" value="0" />
And add 2 events:
window.addEventListener( 'focus', function ( event ) {
var obj = document.querySelector('#isActiveExt');
if ( !parseInt( obj.value ) ) {
obj.value = 1;
// Re-enumerates all layers and artboards
}
});
window.addEventListener( 'blur', function ( event ) {
var obj = document.querySelector('#isActiveExt');
if ( parseInt( obj.value ) ) {
obj.value = 0;
}
});
Description of the method:
When the user activates expansion, there should automatically update all layers and artboards.
As a complement, function create thumbnails layers and artboards, you can add in the following events:
new CSinterface().addEventListener('documentAfterActivate');
new CSinterface().addEventListener('documentAfterDeactivate');
new CSinterface().addEventListener('applicationActivate');
Copy link to clipboard
Copied
Thanks Alexander Ladygin. This helps a lot.
Perhaps the end user will be more happy to see effect as soon as he performs action rather than clicking on extension(to gain foucus).
CarlosCanto - I tried to add kAIDocumentChangedNotifier(Sent when the contents of a document have changed - as per adobe docs) in my plugin code(.aip) to recieve notification as soon as document is modified. But the notifier handle is activated only on document open, close and save event.
My perception is I should get notified as soon as document gets modified. Surprisingly, there are similar notfiers like kAIDocumentClosedNotifier , kAIDocumentOpenedNotifier, kAIDocumentSavedNotifier , kAIDocumentNewNotifier which does the same work.
Can someone please point me to correct API?
Copy link to clipboard
Copied
You need to build custom CSXS event and dispatch it.
Here is an sample codes:
void samplePluginController::notifyMessage(CustomObject* customObject)
{
stringstream myString; //Build notifiers payload
myString << "<payload><message>" << customObject->GetFullString() << "</message></payload>";
std::string xmlstring = myString.str();
csxs::event::Event event = {"com.adobe.csxs.events.notifyMessage",
csxs::event::kEventScope_Application,
"notifyMessage",
NULL,
xmlstring.c_str()};
htmlPPLib.DispatchEvent(&event);
}
You can reference Marked Objects sample in AI SDK.
Copy link to clipboard
Copied
I want to update the thumbnails on every action user performs on artboard.
Can you briefly explain how can I get control to dispatch event ( when user draws a line on artboard)?
I am confused here.
Copy link to clipboard
Copied
In MarkedObjectsPlugin.cpp, Add notifyer and capture it like below.
//MarkedObjectsPlugin.cpp
CHECK_ERROR
error = sAINotifier->AddNotifier( fPluginRef, "MarkedObjectsPlugin",
kAIDocumentChangedNotifier , &documentChangedNotifier);
...
ASErr MarkedObjectsPlugin::Notify( AINotifierMessage *message )
{
ASErr error = kNoErr;
try
{
...
if ( message->notifier == documentChangedNotifier )
{
fMarkedObjectsPanelController->Clear();
fMarkedObjectsPanelController->UpdateMarkedObjectSelected();
GetMarkedObjects();
}
...
You can find function to call previouse notifyer function.
//MarkedObjectsPanelController.cpp
void MarkedObjectsPanelController::UpdateMarkedObjectSelected( void )
{
// Construct XML string
if ( fMarkedObjectManager == NULL)
return;
int count = fMarkedObjectManager->GetMarkedObjectSize();
if ( count <= 0 )
return;
for(int i = count -1; i >= 0; i--)
{
MarkedObject* markedObject = fMarkedObjectManager->GetMarkedObject(i);
if ( markedObject == NULL ) return;
if ( markedObject->IsSelected() )
{
UpdatePanelByMarkedObject(markedObject, i);
break;
}
}
}
...
void MarkedObjectsPanelController::UpdatePanelByMarkedObject(MarkedObject *markedObject, int index)
{
if ( markedObject == NULL ) return;
AIRealPoint location = markedObject->GetLocation();
stringstream myString;
myString << "<payload><item>" << index << "</item><label>" << markedObject->GetLabel()
<< "</label><ID>" << markedObject->GetID() << "</ID>" << "<locx>" << location.h
<< "</locx>" << "<locy>" << location.v << "</locy></payload>";
std::string xmlstring = myString.str();
//Make custom event and dispatch it
csxs::event::Event event = {"com.adobe.csxs.events.MarkedObjectsUpdatePanel",
csxs::event::kEventScope_Application,
"MarkedObjectsUpdatePanel",
NULL,
xmlstring.c_str()};
fPPLib.DispatchEvent(&event);
}
You can catch dispatched message in CEP Extension like below.
...
csInterface.addEventListener("com.adobe.csxs.events.MarkedObjectsUpdatePanel", updatePanel);
...
function updatePanel(event) {
var xmlData = $.parseXML(event.data);
var $xml = $(xmlData);
if ($xml.find('item').text() != -1) {
var x = $xml.find('locx').text();
var y = $xml.find('locy').text();
var label = $xml.find('label').text();
var id = $xml.find('ID').text();
var itemIndex = $xml.find('item').text();
$('#homeX').val(x);
$('#homeY').val(y);
$('#id').val(id);
$('#label').val(label);
$('input[name="submit"]').removeAttr('disabled');
}
}
Copy link to clipboard
Copied
Thanks Ten A for in detail explanation. I got your point. It really helps.
integrated above things in my code - added kAIDocumentChangedNotifier(Sent when the contents of a document have changed - as per adobe docs) in my plugin code(.aip) to recieve notification as soon as document is modified. But the notifier handle is activated only on document open, close and save event whereas I want a notifier which notifies me as soon as document is edited(not saved, opened, closed etc).
kAIDocumentChangedNotifier appears a bottleneck here.
Does this works for you?
However I found one notifier while skimming through docs. kAIArtSelectionChangedNotifier does exactly as expected. I can live with that.
I am still want to know why kAIDocumentChangedNotifier behaves the way its behaving (it should not as per docs). I must be writing terrible code.
Copy link to clipboard
Copied
Probably, DOCUMENT_CHANGED event fired when activeDocument switched.
However, I found below in ai_hostadapter helper script.
/**
* Sent when either a change in the selected art objects occurs or an artwork modification such as moving a point on a path occurs. You cannot distinguish a selection change from an artwork modification change. There is no notifier than means just one or the other. Receiving this does not necessarily mean that the set of selected objects, as returned AIMatchingArtSuite::GetSelectedArt(), is different.
*/
AIEvent.ART_SELECTION_CHANGED = 'AI Art Selection Changed Notifier';
I think you can catch event using kAIArtSelectionChangedNotifier when document contents changed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now