C#ATIA

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

全てのツールパスの作業平面を変更

こちらの続きのような感じです。
全てのツールパスを無効に一発で! - C#ATIA

プロジェクト流用の為に、全てのツールパスの作業平面(CATIAの座標系)を
設定したいので、マクロにしました。

//pm2019macro
//Set_Axis.mac ver0.0.1
//全てのツールパスを無効にし作業平面をセットする

Function Main() {
	//無効
	call ExecUncalculated()	
	
	//作業平面選択
	string axis = ''
	call SelAxis($axis)
	
	//確認
	call UserConfirmation($axis)
	
	//Axis
	call SetAxis($axis)
		
	//終わり
	message info 'Done'
}

function ExecUncalculated () {
	int st_cnt = 0
	call GetComputedCount($st_cnt)	
	int tmp1 = 0
	$tmp1 = $st_cnt
	int tmp2 = 0
	do {
		INVALIDATE TOOLPATH ALL Yes
		call GetComputedCount($tmp2)
		if $tmp1 == $tmp2 {
			break
		}
		$tmp1 = $tmp2
	} while not $tmp1 == 0
}

function GetComputedCount (output int out) {
	string filter = 'Computed == 1'
	entity list tps = folder('toolpath')
	$out = size(extract(filter($tps , $filter), 'name'))
}

function SetAxis(string axis) {
	call Msgoff() 
	foreach tp in extract(folder('toolpath'), 'name') {
		ACTIVATE TOOLPATH $tp
		EDIT TPPAGE SWWorkplane
		ACTIVATE WORKPLANE $axis
		EDIT TOOLPATH $tp REAPPLYFROMGUI
	}
	call Msgon() 
}

function UserConfirmation(string axis) {
	int dmy = 0
	string list msglst = {'-- 作業平面 --'}
	if length(trim($axis)) < 1 {
		$dmy = add_last($msglst, '(無し)')
	} else {
		$dmy = add_last($msglst, $axis)
	}
	$dmy = add_last($msglst, '全てのツールパスにこの作業平面を設定しますか?')
	$dmy = add_last($msglst, '(全てのツールパスを無効にします)')
	string msg = join($msglst ,crlf)
	
	bool yn = 0
	$yn = query $msg
	if not $yn {
		macro abort
	}
}

function SelAxis(output string axis)  {
	string msg = '作業平面を選択してください'
	$axis = ''
	IF entity_exists('workplane', '') {
	   $axis = $entity('workplane', '').name
	} 
	$axis = input entity workplane $msg	
}

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

function Msgon() {
	graphics unlock
	dialogs error on
	dialogs error on
}

昨日のマクロはこの為の試作でした。