Activity › Forums › Adobe After Effects Expressions › Detecting Vector Art Layers in ExtendScript
-
Detecting Vector Art Layers in ExtendScript
Posted by Jay Brown on June 7, 2016 at 9:37 pmI’m working on a script where I want to detect Text Layers and Vector Art Layers(illustrator/eps files) in order to automatically turn them into Shape Layers
I’ve been using:
if(myComp.layer(a) instanceof TextLayer){
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
}
which works fine for Text but not for Vector Layers.The most I have been able to find is that these Vector Illustrator type files are AVLayers. The problem is, comps, footage, solids and others, are also AVLayers.
If I use the same approach:
if(myComp.layer(a) instanceof AVLayer){
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
}
The script stops working if it can’t execute “Create Shapes from Vector Layers”I noticed that the layer file types I want to effect are all ‘Vector Art’ file types, but I can seem to figure out how to check that.
Any help would be much appreciatedThanks,
-JayJuanluis Vich replied 9 years, 1 month ago 3 Members · 10 Replies -
10 Replies
-
Dan Ebberts
June 7, 2016 at 10:18 pmProbably something like this:
if((myComp.layer(a) instanceof AVLayer) && (myComp.layer(a).source instanceof FootageItem) && (myComp.layer(a).source.mainSource instanceof FileSource)){
var splitName = myComp.layer(a).source.mainSource.file.name.split(".");
if ((splitName[splitName.length-1].toLowerCase() == "ai") || (splitName[splitName.length-1].toLowerCase() == "eps")){
myComp.layer(a).selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
myComp.layer(a).selected = false;
}
}
Dan
-
Jay Brown
June 8, 2016 at 3:02 pmThank you Dan, it works perfect! I haven’t ever used split before, that’s brilliant.
It seems like there should be a way to access the metadata in the Project Panel. In the Project panel the AI and EPS items Type category has “Vector Art” listed. Is it possible to read the project item’s Type category?
-
Juanluis Vich
March 22, 2017 at 6:39 pmhi!
I’m trying to get it working adding the possibility to convert text to shape as well, so if you select a bunch of vector art + text layers they are all converted together, but I cannot make it work properly, I added this to Dan’s code (changing “myComp.layer(a)” with “myLayer” to fit the rest of the working code.
If I select text layers it works well, but if I select both vector and text, it just does the vector conversion:
if((myLayer instanceof TextLayer)){
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
}
any ideas? thanks!
the whole code looks like this:
app.beginUndoGroup("convert");
var myLayers = app.project.activeItem.selectedLayers;
var myLayer;
for (var i = 0; i < myLayers.length; i++){
myLayer = myLayers[i];if((myLayer instanceof AVLayer) && (myLayer.source instanceof FootageItem) && (myLayer.source.mainSource instanceof FileSource)){
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
}
else if((myLayer instanceof TextLayer)){
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
}
}
app.endUndoGroup(); -
Dan Ebberts
March 22, 2017 at 7:15 pmI think the issue is probably that when you execute one of those menu commands, it expects the target layer(s) to be selected, but after the operation, the new layer becomes selected, messing up the next iteration.
Dam
-
Juanluis Vich
March 22, 2017 at 7:33 pmoh! thanks for the idea!
I added this but still not working, I guess it’s not enough for make it work properly? (I played with several selected/unselected combinations, but nothing)
if((myLayer instanceof AVLayer) && (myLayer.source instanceof FootageItem) && (myLayer.source.mainSource instanceof FileSource)){myLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
myLayer.selected = false;}
if((myLayer instanceof TextLayer)){
myLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
myLayer.selected = false;}
anyway, thanks!!
-
Dan Ebberts
March 22, 2017 at 10:07 pmThis seems to work:
function processLayer(theComp,theLayer){
for (var i = 1; i <= theComp.numLayers; i++){
theComp.layer(i).selected = false;
}
if((theLayer instanceof AVLayer) && (theLayer.source instanceof FootageItem) && (theLayer.source.mainSource instanceof FileSource)){
var splitName = theLayer.source.mainSource.file.name.split(".");
if ((splitName[splitName.length-1].toLowerCase() == "ai") || (splitName[splitName.length-1].toLowerCase() == "eps")){
theLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
theLayer.selected = false;
}
}else if (theLayer instanceof TextLayer){
theLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
theLayer.selected = false;
}
}
var myComp = app.project.activeItem;
var myLayers = myComp.selectedLayers;app.beginUndoGroup("convert");
for (var i = 0; i < myLayers.length; i++){
processLayer(myComp, myLayers[i]);
}
app.endUndoGroup();
Dan
-
Juanluis Vich
March 23, 2017 at 2:36 amjust a quick question related to your code,
is there a way to manipulate the new converted layers? How it would be possible to access them?
I’d like to change the label color of these new shape layers, or their opacity, or set some scale values, etc
something like
newLayer.label = 3
etcthanks!!
-
Dan Ebberts
March 23, 2017 at 3:07 amThis should work:
function processLayer(theComp,theLayer){
for (var i = 1; i <= theComp.numLayers; i++){
theComp.layer(i).selected = false;
}
if((theLayer instanceof AVLayer) && (theLayer.source instanceof FootageItem) && (theLayer.source.mainSource instanceof FileSource)){
var splitName = theLayer.source.mainSource.file.name.split(".");
if ((splitName[splitName.length-1].toLowerCase() == "ai") || (splitName[splitName.length-1].toLowerCase() == "eps")){
theLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Vector Layer"));
theLayer.selected = false;
theComp.selectedLayers[0].label = 3;
}
}else if (theLayer instanceof TextLayer){
theLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Create Shapes from Text"));
theLayer.selected = false;
theComp.selectedLayers[0].label = 3;
}
}
var myComp = app.project.activeItem;
var myLayers = myComp.selectedLayers;app.beginUndoGroup("convert");
for (var i = 0; i < myLayers.length; i++){
processLayer(myComp, myLayers[i]);
}
app.endUndoGroup();
Dan
Reply to this Discussion! Login or Sign Up