C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

複数のフォルダを削除する

仕事が薄い時に、日頃の不満を解消したい。

PowerMill内のフォルダを削除したい時が多々あるのですが、
まとめて削除出来ず、一個一個チマチマやるのが辛いです。

一度に複数のフォルダを削除する為のマクロを作りました。

//PMill_Macro2018
//フォルダー削除 ver0.0.1

function main(string args) {
	//フォルダリスト
	string list folderLst = {}
	call GetFolderNameLIST($args, $folderLst)
	if is_empty($folderLst) {
		message error  'フォルダがありません!!'
		return
	}
	
	string msg = '削除するフォルダーを選択してください'
	call Exec_DownMenu($folderLst, $msg, 1, $folderLst)
	if size($folderLst) < 1 {
		return
	}
	
	//削除
	call Msgoff()
	string  path = ""
	foreach fdr in $folderLst {
		$path = $args + '\' + replace($fdr, '@', '\')
		//message info  $path 
		string cmd = 'DELETE ' + $args + ' FOLDER "' + $path + '"'
		call Exec_Cmd(cmd) 
	}
	call Msgon()
	
	//終了
	message info  'Done'	
}

//指定した組み込みルートフォルダ内のフォルダ名を取得
function GetFolderNameLIST(string FolderType, output string list Outlst ) {
	string list Folders = get_folders($FolderType)
	if (size($Folders) == 0) {
		return
   }
   
	string list names={}
	foreach path in $Folders {
		string name = path
		$name = replace($name, $FolderType + '\', '')
		$name = replace($name, '\', '@')
		int dmy = add_last($names,$name)
   }
	$Outlst= $names
	return
}
//コマンド
function Exec_Cmd(string cmd) {
	docommand $cmd
}

function Msgoff() {
	graphics lock
	dialogs message off
	dialogs error off
}

function Msgon() {
	graphics unlock
	dialogs message on
	dialogs error on
}
include downmenu.inc

mainのargsは、"Toolpath"等のフォルダ名で、コンテキストメニューから起動させる
タイプです。

過去に、こちらでフォルダ名を取得するものを作りましたが、
イマイチだった為、Forumにあった方法をパクリ参考に
させてもらいました。
フォルダ名リストを取得する - C#ATIA

又、以前作成したプルダウンリストが必要です。
"group" フォルダは犠牲にした、プルダウンリストライブラリ - C#ATIA