https://www.bilibili.com/video/BV12q4y1P77w/
AE脚本 – 路径反向
ReversePath 没有UI直接使用
ReversePath-UI 在Kbar打开是不带UI的,其他情况是有个按钮界面
支持选中关键帧反向,不选中是全部反向
//author: Charles Bordenave (www.nabscripts.com)(https://aescripts.com/reversemaskpath/)
//modified by JimWho (https://space.bilibili.com/3345602)
(function(thisobj) {
function main(){
var thisComp = app.project.activeItem;
var props = thisComp.selectedProperties;
if (props.length < 1) {
alert("Please select at least one Path !")
}
app.beginUndoGroup("Reverse Shape");
for (var i = 0; i < props.length; i++){
var isShapePath = matchMatchName(props[i],"ADBE Vector Shape - Group");
var isMaskPath = props[i].isMask;
if (isShapePath || isMaskPath) {
if (props[i].isMask){
var selpath = props[i].maskPath;
}else{
var selpath = props[i].path;
}
if (selpath.numKeys == 0){
var myshape = selpath.value;
selpath.setValue(ReverseShape(myshape));
}else{
var keyTimes = new Array();
var shapes = new Array();
if (selpath.selectedKeys.length == 0){
for (var k = 1; k <= selpath.numKeys; k++)
{
var keyTime = selpath.keyTime(k);
var shape = selpath.valueAtTime(keyTime, false);
keyTimes.push(keyTime);
shapes.push(ReverseShape(shape));
}
selpath.setValuesAtTimes(keyTimes, shapes);
}else{
for (var k = 1; k <= selpath.numKeys; k++)
{
if (selpath.keySelected(k))
{
var keyTime = selpath.keyTime(k);
var shape = selpath.valueAtTime(keyTime, false);
keyTimes.push(keyTime);
shapes.push(ReverseShape(shape));
}
}
selpath.setValuesAtTimes(keyTimes, shapes);
}
//no keys selected, change only first key
//var shape = selpath.keyValue(1);
//selpath.setValueAtKey(1, ReverseShape(shape));
}
}}
app.endUndoGroup();
}
function matchMatchName(targetEffect, matchNameString) {
if (targetEffect != null && targetEffect.matchName === matchNameString) {
return targetEffect
} else {
return null
}
}
function ReverseArray(arr) {
arr.reverse();
return arr
}
function ReverseShape(shape) {
var newVerts = ReverseArray(shape.vertices);
var newInTang = ReverseArray(shape.outTangents);
var newOutTang = ReverseArray(shape.inTangents);
if (shape.closed == true) {
newVerts.unshift(newVerts.pop());
newInTang.unshift(newInTang.pop());
newOutTang.unshift(newOutTang.pop());
}
shape.vertices = newVerts;
shape.inTangents = newInTang;
shape.outTangents = newOutTang;
return shape;
}
if (typeof kbar !== "undefined" && kbar.button) {
main();
} else {
UIPanel(thisobj);
}
function UIPanel(thisobject){
var win = thisobject instanceof Panel ? thisobject : new Window("palette", "Reverse Path", undefined, { resizeable: true });
//win.orientation = "row";
win.alignChildren = ["center", "center"];;
button = win.add("button", undefined, "Reverse Path");
button.onClick = function(){
main();
}
win.onResizing = win.onResize = function() {this.layout.resize();};
if (win instanceof Window) {
win.center();
win.show();
} else {
win.layout.layout(true);
win.layout.resize();
}
}
})(this);