C#ATIA

↑タイトル詐欺 主にCATIA V5 の VBA(最近はPMillマクロとFusion360APIが多い)

デフォルト [コンポーネント/残り代] と異なる設定のツールパス名を取得2

こちらの続きです。
デフォルト [コンポーネント/残り代] と異なる設定のツールパス名を取得 - C#ATIA

前回はコンポーネント数は未チェックでしたが、チェックするように修正し
実際に使えそうなレベルにして見ました。

//pm2018 macro
//Find_don't_match_ToolPath.mac ver0.0.2
//デフォルト [コンポーネント/残り代] と異なる設定のツールパス名取得
//---------------------------------------------------------------------------------------------------
//ver0.0.1-完成
//ver0.0.2-コンポーネントチェック追加
//---------------------------------------------------------------------------------------------------

function main() {
	bool debug = 0 //debug mode
	
	//check
	call CanExec()
	
	//start
	call Sw_Start()
	graphics lock

	INFOBOX NEW "***** Toolpath ThicknessSetValues info *****"
	INFOBOX CLEAR FORMAT
	
	//defalt ThicknessSetValues
	call PushInfobox('Getting Surface Defaults Info.' + crlf)
	string list def_tvInfo = {}
	string def_cmp_count = ''
	call Get_defalt_ThicknessSetValuesInfo($def_tvInfo, $def_cmp_count)
	
	//filter
	call PushInfobox('Getting Toolpath Surface Parameter.' + crlf)
	string filter = ''
	call Initfilter($def_tvInfo, $filter)
	
	//pram match toolpath
	entity list tps = folder('toolpath')
	$tps =  filter($tps , $filter)
	
	//components
	call PushInfobox('Getting Toolpath Surface Components')
	string list cmps = {}
	call GetCompsCount($tps, $cmps)
	
	//&components match toolpath
	call GetCompMatchList($tps, $cmps, $def_cmp_count, $tps)
	
	//doesn't match toolpath
	call PushInfobox("Getting doesn't match Toolpath." + crlf + crlf)
	string list all_tps =  extract(folder('toolpath'), 'name') 
	string list match_tps =  extract($tps, 'name') 
	string list unmatch_tps =  subtract($all_tps, $match_tps)
	
	call PushInfobox('デフォルト [コンポーネント/残り代] と異なる設定のツールパスは以下のものです' + crlf)
	//call PushInfobox("It's toolpath that don't match the 'Surface Defaults' values." + crlf)
	call PushInfobox(join($unmatch_tps, crlf))
	
	//finish
	if $debug == 1 {
		string tm = ''
		call Sw_GetTime($tm)
		call PushInfobox(crlf + $tm)
	}
	message info  'Done'
}

//start check
function CanExec() {
	string list msg = {}
	int dmy = 0
	//toolpath
	if size(folder('toolpath')) <1 {
		 $dmy = add_last($msg, 'There is no toolpath to check.')
	}
	if size(folder('model')) <1 {
		 $dmy = add_last($msg, 'The model has not been imported.')
	}
	if not is_empty($msg) {
		message warn join($msg, crlf)
		macro abort
	}
}

//Match components
function GetCompMatchList(entity list tps, string list cmps, 
					string def_cmp, output entity list out) {
	int list rng = {}
	call GetRangeLst(0, size($tps), $rng)
	$rng = reverse($rng)
	bool dmy = 0
	foreach idx in $rng {
		if $cmps == $def_cmp {
			$dmy = remove($tps, $idx)
		}
	}
	$out = $tps
}

//Toolpath components
function GetToolpathCompsCount(entity tp, output string out) {
	int list tv_rng = {}
	call GetRangeLst(0, size($tp.ThicknessSetValues), $tv_rng)
	
	int list cmps = {}
	int dmy = 0
	int surf_cnt = -1
	
	foreach idx in $tv_rng {
		$surf_cnt = -1
		object tv =  $tp.ThicknessSetValues[$idx]
		DELETE SELECTION
		EDIT THICKNESS DEFAULTLIST UPDATE
		\r
		$idx  NEW
		\r
		EDIT THICKNESS SELECT
		call GetSelSurfCount($surf_cnt)
		$dmy = add_last($cmps, $surf_cnt)
	}
	$out = join($cmps, ',')
}

//toolpath_list components
function GetCompsCount(entity list tps, output string list out) {
	$out = {}
	string cmp = ''
	int dmy = 0
	foreach tp in tps {	
		call GetToolpathCompsCount($tp, $cmp)
		$dmy = add_last($out, $cmp)
		call PushInfobox(' .' )
	}
	call PushInfobox(crlf)
}

//select surface count
function GetSelSurfCount(output int num) {
	string $TraceFilePath = macro_path(false) + "\selsurf.txt"
	string list txts = {}
	ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
	TRACEFILE OPEN $TraceFilePath
	PRINT SELSURFACE
	TRACEFILE CLOSE
	ECHO ON DCPDEBUG TRACE COMMAND ACCEPT
	
	FILE OPEN $TraceFilePath FOR READ AS Input
	FILE READ $txts FROM Input
	FILE CLOSE Input
	DELETE FILE $TraceFilePath

	$num = size($txts) - 1
}

//filter
function Initfilter(string list tvs, output string out) {
	string list prms = {'Mode', 'UseAxialThickness', 'Thickness', 'AxialThickness'}
	int list prm_rng = {}
	call GetRangeLst(0, size($prms), $prm_rng)
	
	int list tv_rng = {}
	call GetRangeLst(0, size($tvs), $tv_rng)
	
	$out = ''
	string list tmp = {}
	int dmy = 0
	string value = ''
	foreach tv_idx in $tv_rng {
		string list info = tokens($tvs[$tv_idx], ',')
		foreach prm_idx in $prm_rng {
			if $prm_idx == 0 {
				$value = '"' + $info[$prm_idx] + '"'
			} else {
				$value = $info[$prm_idx]
			}
			$dmy = add_last($tmp, 'ThicknessSetValues[' + string($tv_idx) + '].' + $prms[$prm_idx] + ' == ' + $value)
		}
	}
	$out = join($tmp, ' and ')
	print = $out
}

//defalt ThicknessSetValues info
function Get_defalt_ThicknessSetValuesInfo(output string list out, output string cmpcnt) {
	string dmy_tp = ''
	call InitDmyTP($dmy_tp)
	entity tp = entity('toolpath', $dmy_tp)
	
	FORM THICKNESS EDIT THICKNESS TAB DEFAULT
	EDIT THICKNESS TAB COMPONENTS TOOLPATH	
	EDIT TOOLPATH ; THICKNESS CLONE_DEFAULT
	THICKNESS ACCEPT
	object list def_tvs = $tp.ThicknessSetValues
	call GetThickSetValInfo($def_tvs, $out)
	call GetToolpathCompsCount($tp, $cmpcnt)
	DELETE TOOLPATH  $dmy_tp	
}

//ThicknessSetValues info
function GetThickSetValInfo(object list tvs, output string list out) {
	int list rng = {}
	call GetRangeLst(0, size($tvs), $rng)
	string info =''
	string list lst = {}
	int dmy = 0
	
	foreach idx in $rng {
		object tv =  $tvs[$idx]
		$info = $tv.Mode + ',' + $tv.UseAxialThickness + ',' + $tv.Thickness + ',' + $tv.AxialThickness
		$dmy = add_last($lst, $info)
	}
	$out = $lst
}	

//dammy toolpath
function InitDmyTP(output string out) {
	$out = new_entity_name('toolpath')
	IMPORT TEMPLATE ENTITY TOOLPATH TMPLTSELECTORGUI 'Finishing/Constant-Z-Finishing.002.ptf'
	FORM CANCEL STRATEGYSELECTOR\nFORM TOOLPATHIMPORT
	EDIT TOOLPATH $out REAPPLYFROMGUI
	YES
	FORM ACCEPT SFConstZFinishing
}

//range
function GetRangeLst(int start, int count, output int list lst) {
	int num = 0
	$lst = {}
	do {
		int dmy = add_last($lst, $start + $num)
		$num = $num + 1
	} while $num < $count
}

//infobox
function PushInfobox(string msg) {
	INFOBOX STYLE "NORMAL"
	INFOBOX APPEND  $msg
}

//clock on
function Sw_Start() {
	CLOCK RESET QUIT
	CLOCK ON QUIT	
}

//clock off
function Sw_GetTime(output string out) {
	string $TraceFilePath = macro_path(false) + "\clock.txt"
	string list txts = {}
	ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT
	TRACEFILE OPEN $TraceFilePath
	CLOCK OFF QUIT
	CLOCK PRINT QUIT
	TRACEFILE CLOSE
	ECHO ON DCPDEBUG TRACE COMMAND ACCEPT
	
	FILE OPEN $TraceFilePath FOR READ AS Input
	FILE READ $txts FROM Input
	FILE CLOSE Input
	DELETE FILE $TraceFilePath

	$out = $txts[0]
}

コメントが英語な部分は、そのうちフォーラムで良い方法が無いものか? を
質問しようと思っているためです。(コード内の英語を含め、自信なし)

実際に業務で使用したデータでチェックしてみました。
前回のマクロでは
f:id:kandennti:20180528151318p:plain
7秒ほど。

今回のマクロでは
f:id:kandennti:20180528151359p:plain
80秒ほど・・・・ガッカリ。
手動でチェックするのを考えれば、確かに速いけど、
マクロで1分以上はかなり苦痛。