Highlighted

locks and select layers

Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

Hello everybody,

I need a two simple scripts for Indesign

In my active document i have layer1 and layer2

The first script will lock layer1 and then activate layer2

The second script lock layer2 and activate layer1

Regards,

Nick Riviera

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I have edited the code, try it again

 

-Manan

TOPICS
Scripting

Views

347

Likes

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

locks and select layers

Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

Hello everybody,

I need a two simple scripts for Indesign

In my active document i have layer1 and layer2

The first script will lock layer1 and then activate layer2

The second script lock layer2 and activate layer1

Regards,

Nick Riviera

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I have edited the code, try it again

 

-Manan

TOPICS
Scripting

Views

348

Likes

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
Jun 02, 2020 0
Adobe Community Professional ,
Jun 02, 2020

Copy link to clipboard

Copied

 

Try the following, the last line is described as follows

lockandactivate("layer1", "layer2") //This will lock layer1 and activate layer2

If you want to interchange this just change it to

lockandactivate("layer2", "layer1") //This will lock layer2 and activate layer1

 

function lockandactivate(a, b)
{
	var doc = app.activeDocument
	var al = doc.layers.itemByName(a)
	var bl = doc.layers.itemByName(b)
	if(al.isValid && bl.isValid)
	{
		al.locked = true
		bl.locked = false
		doc.activeLayer = bl
	}
	else
		alert("Could not find one of the layers")
}

lockandactivate("layer1", "layer2") //This will lock layer1 and activate layer2

 

Edited

 

-Manan

Likes

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
Reply
Loading...
Jun 02, 2020 0
Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

Thank you for your help

I think it's a small problem and I don't know how to solve it

this function work "lockandactivate("layer1", "layer2") //This will lock layer1 and activate layer2"

but when i run this "lockandactivate("layer2", "layer1") //This will lock layer2 and activate layer1" layer1 remains locked.. should be unlocked

 

Likes

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
Reply
Loading...
Jun 02, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

I have edited the code, try it again

 

-Manan

Likes

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
Reply
Loading...
Jun 03, 2020 0
Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

It works perfectly, thanks

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 02, 2020

Copy link to clipboard

Copied

app.activeDocument.activeLayer = "layer1";
app.activeDocument.layers.itemByName("layer2").locked = true;

Switch the two for your second script. For more info:

Document object: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html

Layer object:  https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html

Likes

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
Reply
Loading...
Jun 02, 2020 0