• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Stop a layer from being delted in Indesign 2020 using extend script

Community Beginner ,
Apr 01, 2023 Apr 01, 2023

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);
	}
	
}



 

 

TOPICS
Scripting

Views

235

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2023 Apr 01, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 01, 2023 Apr 01, 2023

Copy link to clipboard

Copied

Chat GPT  😛
Couldn't find anything anywhere else so turned to GPT.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2023 Apr 01, 2023

Copy link to clipboard

Copied

You'd have to check/add handlers by pageitem, and if itemLayer.name == "layer to save"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 03, 2023 Apr 03, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2023 Apr 03, 2023

Copy link to clipboard

Copied

LATEST

Can't you just lock the layer? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines