shinsuke matsumoto's blog thing.


Hey, mograph guys & gals out there! One more code for you today because this is the day I launched my new series for sharing basic After Effects scripts. And this is all I can do now to celebrate the wonderful Blend Festival in Vancouver… yep, I coundn’t take part in the party.

Okay, here’s the code for you. This one called “shapePathDirectionToggle” is to toggle the direction of shape layer path. Please take a look.

[Script Code]

app.beginUndoGroup("Shape Path Direction Toggle");
var curComp = app.project.activeItem;
if(curComp != null && curComp instanceof CompItem){
    var selectedLayers = curComp.selectedLayers;
    if(selectedLayers.length > 0){
        for(var i = 0; i < selectedLayers.length; i++){
            if(selectedLayers[i] instanceof ShapeLayer){
                getShapePath(selectedLayers[i].property("ADBE Root Vectors Group"));
            }
        }
    } else {
        alert("Select a shape layer at least.", "Shape Path Direction Toggle");
    }
} else {
    alert("Select a composition first.", "Shape Path Direction Toggle");
}
app.endUndoGroup();



function getShapePath(theProp){
    try{
        var propsNum = theProp.numProperties;
        for(var i = 1; i <= propsNum; i++){
            if(theProp.property(i).matchName == "ADBE Vector Shape - Group"){
                if(theProp.property(i).property("ADBE Vector Shape Direction").value == 1 || theProp.property(i).property("ADBE Vector Shape Direction").value == 2){
                    theProp.property(i).property("ADBE Vector Shape Direction").setValue(3);
                } else if(theProp.property(i).property("ADBE Vector Shape Direction").value == 3){
                    theProp.property(i).property("ADBE Vector Shape Direction").setValue(2);
                }
            }
            if(theProp.property(i).matchName == "ADBE Vector Group"){
                getShapePath(theProp.property(i).property("ADBE Vectors Group"));
            }
        }
    } catch(err){
        alert("Error at line # " + err.line.toString() + "\r" + err.toString());
    }
}

 

[Quick Explanation]
Copy the code & past them into Adobe ExtendScript Toolkit. And in AE, select shape layers, then running the script. So shapePathDirectionToggle script will toggle the direction of all shape paths in the shape layers you selected.

If you have a great script called “ft-Toolbar2” from aescripts, it’s ultra easy to use this script. Create the new button as Javascript in the setting menu in ft-Toolbar2, and then copy & paste the code into the command field like below. So you can toggle the direction of all shape paths in the shape layers you selected.

This script has only a simple function but it’s nice and powerful if you add some more features, I think. Let’s give it a try and share with me!

Anyway, I would much appreciate it if you could give me a feedback. So please don’t hesitate to get in touch with me if you find some errors or better ways. And if you have any request for the series, hit me up on my Twitter. And if you don’t have time to read my crappy article, please follow & check my codes on my GitHub Gist.

 

[Tiny Inside Story]
The other day, talented mographer Seth Eckert tweeted about script feature (below) and I saw it and I wrote this one for my scripting practice. I think cool mographer Adam Plouff has better version of this script because he’s always so much clever than me.

Advertisements

4 Responses to “Crap Sharing for AE Scripting: shapePathDirectionToggle”

  1. Yuan

    Cool script! I have added into my ft-toolbar. It doesn’t work when I applied this to rectangle or ellipse. (maybe it is the problem of my AE version) So I modified twenty fifth row line in your code to make script work with parametric shape
    .
    if(theProp.property(i).matchName == “ADBE Vector Shape – Group” ||theProp.property(i).matchName == “ADBE Vector Shape – Rect” ||theProp.property(i).matchName == “ADBE Vector Shape – Ellipse” ||theProp.property(i).matchName == “ADBE Vector Shape – Star”)

    Reply
    • beatgram

      Thank you, Yuan.
      I wrote this code for “Shape Path”, so it doesn’t work for Parametric shapes. Anyway, thanks for play around with and modify my code.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

%d bloggers like this: