Last active
May 20, 2017 04:14
-
-
Save deathponta/4567d5d6c38f5370d88b0a7c65e537be to your computer and use it in GitHub Desktop.
複数maxシーン内のノード名を一括リネーム
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
/* | |
Created on 2017.5.16 | |
Author deathponta | |
指定フォルダ内にある全Maxファイル内の、指定したノードをリネームする | |
*/ | |
fn Main _tgtPath _srcNodeName _newNodeName=( | |
d = DotNetClass "System.IO.Directory" | |
p = DotNetClass "System.IO.Path" | |
-- 指定されたディレクトリが存在しなかったら抜ける | |
if (d.Exists(_tgtPath) == false) do( | |
messageBox "ディレクトリが存在しません" | |
return false | |
) | |
-- フォルダ以下の全ファイルを取得 | |
files = d.GetFiles( _tgtPath ) | |
-- .maxファイルのみを集める | |
maxFiles = #() | |
for file in files do( | |
if p.GetExtension(file) == ".max" do( | |
Append maxFiles file | |
) | |
) | |
-- Maxファイルが無かったら抜ける | |
if maxFiles.count == 0 do( | |
messageBox "Maxファイルが存在しません" | |
return false | |
) | |
-- リネーム処理 | |
unprocessedFiles = #() -- 処理されなかったファイルネーム格納用 | |
for maxFile in maxFiles do( | |
-- useFileUnits:false の場合、ファイル オブジェクトは現在のシステム単位スケールに再スケールされます。 | |
LoadMaxFile maxFile useFileUnits:false | |
-- シーン内で指定ノードが存在しなければ、処理を行わずに continue | |
srcObj = execute( "$'" + _srcNodeName + "'" ) | |
if srcObj != undefined then( | |
srcObj.name = _newNodeName | |
)else( | |
Append unprocessedFiles maxFile | |
continue | |
) | |
SaveMaxFile maxFile | |
) | |
---------------------------------------- | |
-- どのファイルでリネームが成功しなかったかをプリント | |
ClearListener() | |
-- リネームが成功した場合 | |
if unprocessedFiles.count == 0 do( | |
print ("全Maxファイル内の " + _srcNodeName + " を " + _newNodeName + " にリネームしました") | |
return false | |
) | |
-- リネーム失敗ファイルが1つ以上ある場合 | |
print "------------------------------" | |
print ("下記のファイルには " + _srcNodeName + " というノードが存在しません。" ) | |
print "------------------------------" | |
for unprocessedFile in unprocessedFiles do( | |
print (p.GetFileName( unprocessedFile )) | |
) | |
---------------------------------------- | |
) | |
---------------------------------------- | |
-- UI | |
try( DestroyDialog rol_renameNodeNameAllMaxFile )catch() | |
rollout rol_renameNodeNameAllMaxFile "RenameNodeNameAllMaxFile" width:304 height:112( | |
edittext edt_tgtPath "path" pos:[8,32] width:280 height:16 | |
label lbl1 "指定したフォルダ以下の全Maxファイル内のノードをリネーム" pos:[8,8] width:304 height:16 | |
button btn_exec "実行" pos:[8,80] width:280 height:24 tooltip:"※Enter押しっぱにして下さい" | |
editText edt_srcNodeName "" pos:[8,56] width:120 height:17 | |
editText edt_newNodeName "" pos:[160,56] width:128 height:17 | |
label lbl2 "-->" pos:[136,56] width:24 height:16 | |
on btn_exec pressed do( | |
Main edt_tgtPath.text edt_srcNodeName.text edt_newNodeName.text | |
) | |
) | |
CreateDialog rol_renameNodeNameAllMaxFile | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment