Copy link to clipboard
Copied
Hi Guys,
I am trying to stop a layer from being deletedin Indesign 2020 but i am unable to do so. Basically i have been tagging the layers on some condtion and then if user ties to delete the tagged layer i want to show alert message and then stop the event from executing.
I tried adding "beforeDelete" event listner to layer but it did not work as it was not called. Tried with "beforeLayerDelete". I am not sure whcih event to be use. Use it on Individual layer or layer object. I have been stuck on this since yesterday.
I need some guidence as to which event to use ?? I am trying to add the event listners inside the afterOpen event.
Hirerarchy is like this.
1) BeforeOpen
2) AfterOpen
a) Inside adding event listner for doc [AfterOpen]. This event listner when triggered after the doc is opened and calls my tagging function. Inside this tagging function , which is tagging some of the layers, i want to add the deleteEventListner for the layer here as tags needs to be added for certian layer hence only tag layes should be stopped from deletion.
function tagStoryLayers(app,containerID) {
try{
var doc = app.activeDocument;
// get all stories for the container
var stories = GetContainerStories(containerID, doc);
for(var i=0; i< stories.length; i++){
var storyName = stories[i];
for (var j = 0; j < doc.layers.length; j++) {
var layer = doc.layers[j];
if (layer.name == storyName) {
layer.label = "IsStoryLabel: True";
layer.addEventListener("beforeDelete",OnBeforeDelete);
}
}
}
}
catch(ex){
alert("Error from tagStoryLayer : " + ex.message);
}
}
Copy link to clipboard
Copied
I don't think if we have any events exposed on the Layer object. Where did you find this beforeDelete event described?
-Manan
Copy link to clipboard
Copied
Chat GPT 😛
Couldn't find anything anywhere else so turned to GPT.
Copy link to clipboard
Copied
You'd have to check/add handlers by pageitem, and if itemLayer.name == "layer to save"
Copy link to clipboard
Copied
My issue is with the deletion of layers not with the deletion of page item. What i want is stop the deletion of certian layer. Which layes , that i have already done, but now the question is how to. that is what i have been struggleing with
Copy link to clipboard
Copied
Can't you just lock the layer?