C#ATIA

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

アクティブなブロックを未計算ツールパスに反映させる

恐らくどの3DCAMでも、類似した工程を製作する際は
予め作成しておいた雛形を流用するのだろうと思います。

PowerMillにもテンプレートオブジェクトと言う機能が有り、非常に
便利なのですが、ちょっと困る部分もあったりします。

テンプレートを呼び出した際、各ツールパスが切削領域を設定する
ブロックが記録した際サイズのままになってしまいます。
これを一つずつ修正するなんて、僕には有り得ないお話。

なので、アクティブなブロックを未計算ツールパスに反映させる
マクロを作ってみました。

//pm2017 macro sample_Active_Block_Copy.mac
//アクティブなブロックを未計算ツールパスに反映させる

function main() {
	//確認
	string msg = ''
	call Can_Exec() 
	
	//ブロックタイプ
	if block.type != "box"  {
		message wran  'ボックスタイプのブロックしか対応出来ません!!'
		macro abort
	}
	
	//ブロックサイズ
	real list Limits = {}
	call Get_BlockSize($Limits)
	string cmd = ''
	call Get_CmdString($Limits, $cmd)
	
	//未計算パス
	string list paths = extract(filter(folder('toolpath'), 'Computed == 0'), 'Name')
	if is_empty(paths)  {
		message wran  '未計算のツールパスが見つかりませんでした'
		macro abort
	}
	
 	//ユーザー選択
	call Lst_ToString($paths, crlf, $msg) 
	$msg = '以下のツールパス全て、ブロックを修正しますか?' + crlf + $msg
	bool yn = 0
	$yn = QUERY $msg
	if not $yn {
		//選択用ダミー作成
		call Create_DmyGroup($paths)
		if is_empty(folder('group')) {
			message error  'エラーです。中止します(エラー_Group)'
			macro abort
		}		
	
		$msg = '現在のブロックを反映する' + crlf + 'ツールパスを選択してください' 
		entity list grps =  input entity multiple group $msg
		DELETE GROUP ALL
		if is_empty(grps) {
			macro abort
		}	
		$paths = extract(grps , 'name')
	}
	
	//ブロックコピー
	call DialogOff()
	call Set_BlockSize($paths, $cmd)
	call DialogOn()
}

//コード取得
function Get_CmdString(real list Limits, output string OutTxt) {
	string txt = ''
	$txt =  $txt + 'EDIT BLOCK XMIN "' + string($Limits[0]) + '"' + crlf
	$txt =  $txt + 'EDIT BLOCK XMAX "' + string($Limits[1]) + '"' + crlf
	$txt =  $txt + 'EDIT BLOCK YMIN "' + string($Limits[2]) + '"' + crlf
	$txt =  $txt + 'EDIT BLOCK YMAX "' + string($Limits[3]) + '"' + crlf
	$txt =  $txt + 'EDIT BLOCK ZMIN "' + string($Limits[4]) + '"' + crlf
	$txt =  $txt + 'EDIT BLOCK ZMAX "' + string($Limits[5]) + '"' + crlf
	$OutTxt = $txt
}

//ブロックコピー
function Set_BlockSize(string list Lst, string Cmd) {
	foreach path in $Lst {
		ACTIVATE TOOLPATH $path
		EDIT BLOCK ALL UNLOCK
		EDIT BLOCKTYPE BOX
		EDIT BLOCK COORDINATE WORKPLANE
		call Exec_Cmd($cmd)
		EDIT BLOCK ALL LOCK
		EDIT TOOLPATH $path REAPPLYFROMGUI
	}
}

//コマンド
function Exec_Cmd(string cmd) {
	docommand $cmd
}

//ブロックサイズ取得
function Get_BlockSize(output real list OutLst) {
	real list lst = {}
	int dmy = 0
	real vlu = 0
	$dmy = add_last($lst, round(block.limits.xmin,4))
	$dmy = add_last($lst, round(block.limits.xmax,4))
	$dmy = add_last($lst, round(block.limits.ymin,4))
	$dmy = add_last($lst, round(block.limits.ymax,4))
	$dmy = add_last($lst, round(block.limits.zmin,4))
	$dmy = add_last($lst, round(block.limits.zmax,4))
	$OutLst = $lst
}

//選択用ダミー作成
function Create_DmyGroup(string list paths) {
	foreach txt in $paths {
		CREATE GROUP ;
		RENAME Group "1" $txt
	}
}

//条件確認
function Can_Exec() {
	if not (is_empty(folder('group'))) {
		string msg = 'グループフォルダをクリアします。' + crlf + '宜しいですか?'
		bool yn = 0
		$yn = QUERY $msg
		if not $yn {
			macro abort
		}
		DELETE GROUP ALL
	}
}

//ダイアログ類オン
function DialogOn() {
	GRAPHICS UNLOCK
	DIALOGS MESSAGE ON
	DIALOGS ERROR ON
	ECHO ON DCPDEBUG TRACE COMMAND ACCEPT
}

//ダイアログ類オフ
function DialogOff() {
	GRAPHICS LOCK
	DIALOGS MESSAGE OFF
	DIALOGS ERROR OFF
	ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
}

//リストから文字列
function Lst_ToString(string list Lst , string Delimiter , output string Outtxt) {
	string txt = ''
	foreach itm in $Lst {
		$txt = $txt + $itm + $Delimiter
	}
	int lng = length($txt) - length($Delimiter)
	$Outtxt = substring($txt , 0 , $lng)
	return
}

まずアクティブなブロックを決め(BOXタイプのみ)、マクロを実行すると
ブロックサイズを修正します。

実際に実行した動画はこちらです。

・・・何やっているか全くわからないと思います。

2回目にマクロを実行した際のプルダウンリストの動きは、前回の最後に
記載した方法で実現させています。
PowerMillマクロのダイアログ類 - C#ATIA
その為、"group" フォルダは犠牲にしています。

(ひょっとしたら全てを一度に直す機能が標準コマンドであるのかな?)