こちらの続きです。
プロジェクトの情報部分をインポート・エクスポートする1 - C#ATIA
先日作ったエクスポートしたファイルをインポートする為のマクロです。
//pm2018 macro //ProjInfoIpt.mac ver0.0.1 //PMillプロジェクト情報部のインポート //-------------------------------------------------------------------- //ver0.0.1-完成 //-------------------------------------------------------------------- function main() { //ファイルの選択 string path = '' call SelFile($path) //存在チェック string msg = '' if not file_exists($path) { $msg = '指定ファイルが存在しません!!' message warn $msg macro abort } //読み込み string list txts = {} call ReadFile($path, $txts) string list infos = tokens($txts[0], ',') if size($infos) < 3 { $msg = '指定したファイルが不正です!!' message warn $msg macro abort } //確認 $msg = '' $msg = $msg + '顧客名 : ' + $infos[0] + crlf $msg = $msg + 'パーツ名 : ' + $infos[1] + crlf $msg = $msg + '注文番号 : ' + $infos[2] + crlf $msg = $msg + 'をインポートしますか?' bool yn = 0 $yn = QUERY $msg if not $yn { macro abort } //インポート string list prms ={'Customer', 'PartName', 'OrderNumber'} string cmd = '' foreach i in {0,1,2} { $cmd = 'EDIT PAR "project.' + $prms[i] + '" "' +infos[i] +'"' docommand $cmd } message info 'Done' } /////////////// //ファイルの選択 function SelFile(output string out) { string title = 'PMillプロジェクトコメント' string filter = 'PMillプロジェクトコメント(.PmCmt)|*.PmCmt|' string defpath = '' call GetParentDir($defpath) $out = fileselect $title $filter $defpath if length($out) < 1 { macro abort } } //プロジェクトの一個上のパス取得 何か方法あるのかな? function GetParentDir(output string out) { string s = project_pathname(0) int p1 = -1 int p2 = 0 while ($p2 > -1) { $p1 = position($s, '/', $p2) if $p1 < 0 { break } $p2 = $p1 + 1 } $out= substring($s, 0, $p2 -1) } //ファイル読み込み function ReadFile(string path, output string list out) { file open $path for read as f file read $out from f file close f }
案の定、最低限のチェックしかしていません。