ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Detecting Vector Art Layers in ExtendScript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jay Brown
Detecting Vector Art Layers in ExtendScript
on Jun 7, 2016 at 9:37:48 pm
Last Edited By Jay Brown on Jun 7, 2016 at 10:12:13 pm

I'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 appreciated

Thanks,
-Jay


Return to posts index


Dan Ebberts
Re: Detecting Vector Art Layers in ExtendScript
on Jun 7, 2016 at 10:18:37 pm

Probably 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



Return to posts index

Jay Brown
Re: Detecting Vector Art Layers in ExtendScript
on Jun 8, 2016 at 3:02:41 pm

Thank 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?


Return to posts index


JuanLuis Vich
Re: Detecting Vector Art Layers in ExtendScript
on Mar 22, 2017 at 6:39:52 pm

hi!
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();



Return to posts index

Dan Ebberts
Re: Detecting Vector Art Layers in ExtendScript
on Mar 22, 2017 at 7:15:47 pm

I 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



Return to posts index

JuanLuis Vich
Re: Detecting Vector Art Layers in ExtendScript
on Mar 22, 2017 at 7:33:56 pm

oh! 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!!


Return to posts index


Dan Ebberts
Re: Detecting Vector Art Layers in ExtendScript
on Mar 22, 2017 at 10:07:35 pm

This 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



Return to posts index

JuanLuis Vich
Re: Detecting Vector Art Layers in ExtendScript
on Mar 22, 2017 at 11:37:04 pm

awesome!!! thank you!!!


Return to posts index

JuanLuis Vich
Re: Detecting Vector Art Layers in ExtendScript
on Mar 23, 2017 at 2:36:42 am

just 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
etc

thanks!!


Return to posts index

Dan Ebberts
Re: Detecting Vector Art Layers in ExtendScript
on Mar 23, 2017 at 3:07:15 am

This 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



Return to posts index

JuanLuis Vich
Re: Detecting Vector Art Layers in ExtendScript
on Mar 23, 2017 at 4:14:04 am

super!! infinite thanks!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]