Last active
November 1, 2016 17:50
-
-
Save chobie/70a4edc2e35e6626fd2a89e3315eaf39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// シェイプレイヤーのコンテンツの位置からトランスーフォームの位置がシェイプの中心点に来るように修正します。 | |
// | |
// [MEMO] | |
// シェイプレイヤーは作成時にコンポジションの中心点に位置をあわせます。 | |
// 複数シェイプを格納できるようにするためにこのようにしてあるのですが、一つだけしかシェイプを | |
// 含めない場合はシェイプの中心点にトランスフォームの中心がこないので余計なお世話だったりします。 | |
// このスクリプトはシェイプレイヤーのシェイプの位置情報をクリアし、レイヤーの位置情報が中心点に来るように修正をします。 | |
// | |
// ・複数シェイプを含むシェイプレイヤーは対応していません。キーフレームなども考慮しません。 | |
// ・多分変な処理はしませんが大事なファイルであれば保存しておいてから作業をしてください | |
// | |
// The MIT License (MIT) | |
// Copyright (c) 2016 chobi_e | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | |
// associated documentation files (the "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |
// subject to the following conditions: | |
// The above copyright notice and this permission notice shall be included in all copies or substantial | |
// portions of the Software. | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES | |
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | |
// OR OTHER DEALINGS IN THE SOFTWARE. | |
(function() { | |
var curItem = app.project.activeItem; | |
if (!(curItem instanceof CompItem)) { | |
alert("コンポジションを選択してください。"); | |
return false; | |
} | |
var selectedLayers = curItem.selectedLayers; | |
if (selectedLayers.length == 0) { | |
alert("選択されているレイヤーがないみたいです。"); | |
return false; | |
} | |
// 選択されているレイヤーの数だけ処理を行います | |
for (var i = 0; i < selectedLayers.length; i++) { | |
var target = selectedLayers[i]; | |
if (target.matchName != "ADBE Vector Layer") { | |
continue; | |
} | |
var contents = matchProperty(target, "ADBE Root Vectors Group"); | |
if (contents == undefined) { | |
alert("コンテンツが無いみたいです"); | |
return false; | |
} | |
if (contents != undefined && contents.numProperties != 1) { | |
alert("複数コンテンツが有るシェイプレイヤーには処理を行えません。"); | |
continue; | |
} | |
// シェイプの0フレの位置をメモしつつ、クリアします | |
obj = matchProperty(target, "ADBE Vector Position"); | |
var pos = obj.valueAtTime(0, false); | |
obj.setValue([0, 0]); | |
obj = matchProperty(target, "ADBE Position"); | |
// トランスフォームにメモした値を加算して中心点が来るようにします | |
var pos2 = obj.valueAtTime(0, true); | |
obj.setValue([pos2[0] + pos[0], pos2[1] + pos[1]]); | |
} | |
return true; | |
})(); | |
function matchProperty(obj, matchName) { | |
var stack = [obj]; | |
while (stack.length > 0) { | |
var node = stack.pop(); | |
if (node.matchName == matchName) { | |
return node; | |
} | |
for (var i = node.numProperties; i > 0; i--) { | |
stack.push(node.property(i)); | |
} | |
} | |
return undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment