Copy link to clipboard
Copied
Hi,
Can someone help us? We are developing a panel using Javascript and CEP. How can we detect if a user changes horizontalMeasurementUnits or verticalMeasurement units? We have already tried adding an eventlistener to viewPreference object but the event is not triggered and the callback is never called.
Thanks
Jean-Lou
Hi Jean-Lou,
Actually, there is one way to tackle this given that when the user switches to another unit, (s)he basically calls a menu action. And menu actions can have event listeners attached to the invokation event.
//Listening to calls to "Millimeters" menu
#targetengine "invoking_mm_unit"
//Storing if event listener has been already set (in case script is called multiple times)
var isSet = isSet || false;
//Adding listener to "Millimeters" menu action call
(function main(){
//VARS
...
Copy link to clipboard
Copied
Hi Jean-Lou,
Actually, there is one way to tackle this given that when the user switches to another unit, (s)he basically calls a menu action. And menu actions can have event listeners attached to the invokation event.
//Listening to calls to "Millimeters" menu
#targetengine "invoking_mm_unit"
//Storing if event listener has been already set (in case script is called multiple times)
var isSet = isSet || false;
//Adding listener to "Millimeters" menu action call
(function main(){
//VARS
var
//The reference to the "Milimeters" menu action
ma = app.menuActions.itemByName("$ID/Millimeters"),
//The event handler function
evHandler = function(ev){
alert("Doc unit has just been set to Millimeters");
};
//If the event listener hasn't been set yet, let's add it.
if ( !isSet ) {
//Let's store the info
isSet = true;
//Let's add the event listener to the menu invokation
ma.addEventListener ("afterInvoke", evHandler);
}
})();
So there, we want to catch the moment when user clicks on the "Millimeter" item either in horizontal or vertical ruler, and in the cross section.
Hope that helps,
Loic