Mobile app version of vmapp.org
Login or Join
Angela777

: Indesign API built-in events paragraph-style Does Indesign trigger any events when a paragraph style object does change? Or is there any built in javascript functionality that can observe an object?

@Angela777

Posted in: #AdobeIndesign #IndesignScripting

Does Indesign trigger any events when a paragraph style object does change? Or is there any built in javascript functionality that can observe an object? Object.obserce and Proxy are not working in CS6.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela777

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley591

The documentation states that you can attach event listeners to DOM objects such as myParaStyle.addEventListener but I could never got something to work with those.

But you can use an idleEvent listener and look around at possible styles edits:
#targetengine "onAfterSelectionChanged"
var main = function() {

var currDocId, stylesDB = {};


var onAfterParagraphStyleEdit = function ( evt ) {
var doc = evt.parent, docId;
if ( !app.documents.length ) return;
doc = app.activeDocument;
docId = doc.id;

if ( !currDocId
||
currDocId!=docId ) {
currDocId = docId;
stylesDB = getStylesDB(doc);
return;
}

try {
compareStyles ( doc, stylesDB ) ;
}
catch(err) {
alert ( err.line+"//"+err.message );
}
}

var it = app.idleTasks.itemByName ("onAfterParagraphStyleEdit" );

if ( !it.isValid ) {
it =app.idleTasks.add({name:"onAfterParagraphStyleEdit", sleep:100});
it.addEventListener(IdleEvent.ON_IDLE, onAfterParagraphStyleEdit, false);
}
}
main();
var compareStyles = function ( doc, db ) {
var pss = doc.allParagraphStyles, ps, psId, psProps,
n = pss.length, diffs = [];

while ( n-- ) {
ps = pss[n];
psId = ps.id;
if ( !db[psId] )  {
db[psId] = ps.properties.toSource();
}
else {
psProps = ps.properties.toSource();
if ( db[psId] != psProps) {
diffs.push ( ps.name +"["+ps.id+"]" );
db[psId] = psProps;
}
}
}

diffs.length && alert("Those styles were modified…r"+diffs.join("r"
) );
}
var getStylesDB = function ( doc ) {
var db = {};
var pss = doc.allParagraphStyles, ps,
n = pss.length;

while ( n-- ) {
ps = pss[n];
db[pss[n].id] = ps.properties.toSource();
}

return db;
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme