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

How to copy layer structure by number sequence?

Contributor ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi,
I have a layer structure. I want to copy it according to a number sequence, that is, copy 1, 2, 3, 4, 5, 6, 7, 8... 100 layers. Their structures are the same, but the name of the main layer should be named according to the number. 1, 2, 3... Etc., but the names of all other sub layers cannot be changed. I wonder if there is such a script that can be implemented.
There is a "Copy Layer" command in the layer menu to copy the entire layer structure, but the word "copy" will be automatically added to all layer names, and the main layer cannot be named according to the number sequence, and the names need to be modified one by one, including all sub layer names. This is a very time-consuming and nerve wracking work, so try to use scripts to see if this can be achieved. Thank you.

 

Layer structure to copy:

a.JPG


Effect to be achieved:

b.jpg

TOPICS
Scripting

Views

386

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

correct answers 1 Correct answer

Contributor , Aug 20, 2022 Aug 20, 2022

Votes

Translate

Translate
Adobe
Guide ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Just to be clear, you want to duplicate an empty layer's structure (one layer and its sublayers), not any items on those layers/sublayers?

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
Contributor ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Sorry, I didn't make it clear.
Not only the layer structure, it should also copy all the items in the layers/sublayers if the layers/sublayers have items.

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
Contributor ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

Is there a forum God to help me look at it? 

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
Contributor ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Thanks @Silly-V  @Charu Rajput for help and ideas.

 

I can solve 80% of my problems with the following script, but I haven't thought of a good way to keep the names of all the copied sub layers consistent with the source layers.

 

// Need to import “target layer” and “dupelayer” actions in the action panel in advance.
// The target layer ”1” to be copied is a sub layer under a parent layer.

function highlightLayerInContainer (targetLayer) {
		var someTempPath = targetLayer.pathItems.rectangle(0, 0, 200, 200);
    someTempPath.name = "TEMP [for highlighting]";
		app.activeDocument.selection =  null;
		someTempPath.selected = true;
		app.doScript("target layer", "Test Set 2"); 
		someTempPath.remove();
  }

    for (var i=1;i<199;i++) {
        highlightLayerInContainer(app.activeDocument.layers[0].layers[0]); // The target layer ”1” to be copied is a sub layer under a parent layer.
        app.doScript("DupeLayer", "Test Set 2");
        app.activeDocument.layers[0].layers[0].name=i+1; //number sequence name
    }

 

I would be greatly appreciated if you could give me help or advice, Thanks in advance!

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
Contributor ,
Aug 20, 2022 Aug 20, 2022

Copy link to clipboard

Copied

LATEST

Thanks @Silly-V  @jduncan @Charu Rajput and @Disposition_Dev for help and ideas.  I divided the problem of this post into the following three parts to solve it. Finally, it was solved:

 

1) Highlighted Layer

https://community.adobe.com/t5/illustrator-discussions/how-to-highlighted-select-a-specified-layer/m... 

 

2)Duplicate Layer

https://community.adobe.com/t5/illustrator-discussions/quot-duplicate-layer-quot-command-in-script/m... 

 

3)Rename Layer

https://community.adobe.com/t5/illustrator-discussions/how-to-move-and-align-objects-with-scripts/m-... 

 

Here I share the complete code I have sorted out. I hope this can be helpful to people with similar problems. Thanks!

// Highlihgt and duplicate layer
function highlightLayerInContainer (targetLayer) {
		var someTempPath = targetLayer.pathItems.rectangle(0, 0, 200, 200);
    someTempPath.name = "TEMP [for highlighting]";
		app.activeDocument.selection =  null;
		someTempPath.selected = true;
		app.doScript("target layer", "Test Set 2");
		someTempPath.remove();
  }

    for (var i=1;i<199;i++) {
        highlightLayerInContainer(app.activeDocument.layers[0].layers[0]); // my target layer was a sublayer
        app.doScript("DupeLayer", "Test Set 2");
        app.activeDocument.layers[0].layers[0].name=i+1  // number sequence name, target layer name set to "1"
    }

var doc = app.activeDocument;
var layers = doc.layers;

// Rename all sublayers
for (var i = doc.layers.length - 1; i > -1; i--) {

  recursiveRename(doc.layers[i]);
}

function recursiveRename(parent) {
  for (var i = 0; i < parent.layers.length; i++) {
    parent.layers[i].name = parent.layers[i].name.replace(/\scopy.*$/, "");
    recursiveRename(parent.layers[i]);
  }
}

// Action file
/version 3
/name [ 10
	54657374205365742032
]
/isOpen 1
/actionCount 2
/action-1 {
	/name [ 9
		447570654c61796572
	]
	/keyIndex 0
	/colorIndex 0
	/isOpen 1
	/eventCount 1
	/event-1 {
		/useRulersIn1stQuadrant 0
		/internalName (ai_plugin_Layer)
		/localizedName [ 5
			4c61796572
		]
		/isOpen 1
		/isOn 1
		/hasDialog 0
		/parameterCount 2
		/parameter-1 {
			/key 1836411236
			/showInPalette -1
			/type (integer)
			/value 1
		}
		/parameter-2 {
			/key 1851878757
			/showInPalette -1
			/type (ustring)
			/value [ 19
				4475706c69636174652053656c656374696f6e
			]
		}
	}
}
/action-2 {
	/name [ 12
		746172676574206c61796572
	]
	/keyIndex 0
	/colorIndex 0
	/isOpen 1
	/eventCount 3
	/event-1 {
		/useRulersIn1stQuadrant 0
		/internalName (ai_plugin_Layer)
		/localizedName [ 5
			4c61796572
		]
		/isOpen 0
		/isOn 1
		/hasDialog 0
		/parameterCount 2
		/parameter-1 {
			/key 1836411236
			/showInPalette -1
			/type (integer)
			/value 19
		}
		/parameter-2 {
			/key 1851878757
			/showInPalette -1
			/type (ustring)
			/value [ 13
				4c6f63617465204f626a656374
			]
		}
	}
	/event-2 {
		/useRulersIn1stQuadrant 0
		/internalName (ai_plugin_Layer)
		/localizedName [ 5
			4c61796572
		]
		/isOpen 0
		/isOn 1
		/hasDialog 0
		/parameterCount 1
		/parameter-1 {
			/key 1836411236
			/showInPalette -1
			/type (integer)
			/value 24
		}
	}
	/event-3 {
		/useRulersIn1stQuadrant 0
		/internalName (ai_plugin_Layer)
		/localizedName [ 5
			4c61796572
		]
		/isOpen 0
		/isOn 1
		/hasDialog 0
		/parameterCount 1
		/parameter-1 {
			/key 1836411236
			/showInPalette -1
			/type (integer)
			/value 25
		}
	}
}

 

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