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.
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.
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.
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.
Copy link to clipboard
Copied
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.