Last active
August 20, 2016 17:17
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var activeComp = app.project.activeItem; | |
function main() { | |
var markers = null; | |
if (activeComp instanceof CompItem == false) { | |
alert("コンポが選択されていません。"); | |
return; | |
} | |
if (activeComp.selectedLayers.length > 1) { | |
alert ("レイヤーを1つだけ選択するか、コンポのみ選択してください。\nレイヤーを選択していない場合はアクティブなコンポのマーカーが使われます。"); | |
return; | |
} else if (activeComp.selectedLayers.length == 1) { | |
markers = activeComp.selectedLayers[0].property("Marker"); | |
} else if (activeComp.selectedLayers.length == 0) { | |
markers = getCompMarker(activeComp); | |
} | |
if (markers.numKeys < 2) { | |
alert ("選択されているレイヤーかコンポにマーカーが2つ以上ありません。"); | |
return; | |
} | |
var newLight = activeComp.layers.addLight("Marker_Light", [0, 0]); | |
newLight.property("position").setValue([0, 0, 0]); | |
for (var i=1; i<=markers.numKeys; i++) { | |
var keyIdx = newLight.property("position").addKey(markers.keyTime(i)); | |
newLight.property("position").setValueAtKey(keyIdx, [0, 0, i*-100]); | |
newLight.property("position").setInterpolationTypeAtKey(keyIdx, KeyframeInterpolationType.HOLD, KeyframeInterpolationType.HOLD); | |
} | |
var version = parseInt(app.version.split(".")[0]); | |
var msg_export = (version>11)?"MAXON CINEMA 4D Exporter を起動しますか?":"CINEMA 4D Exporter を起動しますか?"; | |
var code_export = (version>11)?5022:5006; | |
var execute = confirm(msg_export); | |
if (execute) app.executeCommand(code_export); | |
} | |
app.beginUndoGroup("markerToC4DasLight"); | |
main(); | |
app.endUndoGroup(); | |
/* | |
AfterEffectsでコンポジションマーカーを取得するスクリプト | |
2013.10.31 by nariakiiwatani | |
MIT License - http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license | |
*/ | |
// マーカーの情報を取得したいコンポジションを渡す | |
function getCompMarker(comp) { | |
// プロジェクトに含まれるコンポジションのリストを取得 | |
function getCompAll(proj) { | |
var ret = []; | |
for(var i = 1; i <= proj.numItems; ++i) { | |
if(proj.item(i) instanceof CompItem) { | |
ret.push(proj.item(i)); | |
} | |
} | |
return ret; | |
} | |
// 配列の差分を取得 | |
function getArrayDiff(a, b) { | |
var ret = []; | |
for(var _a in a) { | |
var found = false; | |
for(var _b in b) { | |
if(a[_a] === b[_b]) { | |
found = true; | |
break; | |
} | |
} | |
if(!found) { | |
ret.push(a[_a]); | |
} | |
} | |
var tmp = a; | |
a = b; | |
b = tmp; | |
for(var _a in a) { | |
var found = false; | |
for(var _b in b) { | |
if(a[_a] === b[_b]) { | |
found = true; | |
break; | |
} | |
} | |
if(!found) { | |
ret.push(a[_a]); | |
} | |
} | |
return ret; | |
} | |
// プロジェクトウィンドウの選択情報を操作するので、操作前の状態を保存しておく | |
var selected = app.project.selection; | |
var selection = []; | |
for(var i = 0; i < selected.length; ++i) { | |
selection.push(selected[i].selected); | |
selected[i].selected = false; | |
} | |
// ここから処理の本体 | |
comp.selected = true; // 書き出し対象のコンポジションを選択状態にする | |
// 「複数アイテムから新規コンポジション」はプロジェクトウィンドウにフォーカスしていないと使えないので強制的にアクティブにする | |
app.project.showWindow(false); | |
app.project.showWindow(true); | |
var allComps = getCompAll(app.project); // コマンド実行前のコンポジションのリスト | |
app.executeCommand(2796); // 「複数アイテムから新規コンポジション」を実行 | |
var added = getArrayDiff(getCompAll(app.project), allComps)[0]; // コマンド実行によって追加されたコンポジションを探す | |
var marker = added.layer(1).marker; // これが欲しかったマーカー! | |
// ここから後片付け | |
added.remove(); // 増やしたコンポジションを削除 | |
comp.selected = false; // 選択状態を解除 | |
for(var i = 0; i < selected.length; ++i) { // スクリプト実行前の選択状態に戻す | |
selected[i].selected = selection[i]; | |
} | |
// マーカー情報を返す | |
return marker; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment