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

Place entire vector layer but only layer

Contributor ,
Jul 03, 2020 Jul 03, 2020

Copy link to clipboard

Copied

To palce a layer with scirpting in illustrator I would do this.

var placeFiles = aLay.placedItems.add();

Where aLay is the document active layer.

I would then do something like this:

placeFiles.file = 'some file name'

My question is.  Is there away to get only a specific layer from a document and then place it into an existing layer?  The layer might have multiple vector items it might not.  Currently the way I'm doing it is selecting each element and then copying that but it takes some time especially if the layer is complex.

 

TOPICS
Scripting

Views

213

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
Adobe
Community Expert ,
Jul 03, 2020 Jul 03, 2020

Copy link to clipboard

Copied

Hi,

Is there away to get only a specific layer from a document

Yes, There is a way to get the specific layer from a document if you give name to your layer. If layer has name you can access this layer by its name. See sample below

 

NOTE: getByName method- return specific topmost layers not sublayers. To get sublayers you need to traverse recursively.

 

var doc = app.activeDocument;
var layerName = "Test"
try {
	var _layer = doc.layers.getByName(layerName);
} catch (e) {
	alert("Layer with name - " + layerName + " doesn't exists")
}

 

See screen shots how it will look in layers panel after giving name.

 

Screenshot 2020-07-04 at 11.01.51 AM.png

 

then place it into an existing layer?

When you are able to access the layer directly by its name. You can placed the item inside easily. For this you have already know how to place the item inside the layer. So complete sample snippet is

var doc = app.activeDocument;
var layerName = "Test";	// Use your layername
var filePath = "~/Desktop/Test.pdf"; // Use your file path that you would like to place.
try {
	var _layer = doc.layers.getByName(layerName);
	var placedItem = _layer.placedItems.add();
	placedItem.file = File(filePath) 
} catch (e) {
	alert("Layer with name - " + layerName + " doesn't exists")
}

 

Let us know if this is what you are looking for.

Best regards

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 ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Thanks for posting this @Charu Rajput!  It's a little confusing.

 

 

var filePath = "~/Desktop/Test.pdf"; // Use your file path that you would like to place.

 

 

Here you are placing the file but I don't want to place the whole file I only want to place a layer from a file. 

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 ,
Jul 13, 2020 Jul 13, 2020

Copy link to clipboard

Copied

LATEST

Hi,

Sorry for the late reply. I don't think this is possible to place a specific layer from a file. But there is a workaround, you can export that specific layer from the file and then place that new exported file. Or if you have sample files, then please share so that we can look and guide you more specifically.

 

Best regards

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