加工步變數
RuntimeApi(API) 提供了多個方法來處理和存取加工步的變數。
預設步輸出資訊
每個加工步都包含豐富的預設輸出資訊,涵蓋來源行、運動學、載荷、力/力矩、功率、熱與磨耗等。
完整的預設步輸出資訊說明,請參考 仿真步輸出資訊(Simulation Step Output)。
Tip
存取預設步資訊範例
PlayNcFile("NC/file1.nc");
// 取得步並存取預設資訊
var step = GetMillingStep(100); // 見下方「存取步資訊」
if (step != null)
{
// 存取預設的步資訊
Message($"ToolId: {step.ToolId}");
Message($"Feedrate: {step.Feedrate_mmdmin} mm/min");
Message($"ChipVolume: {step.ChipVolume_mm3} mm³");
Message($"MaxAbsForce: {step.MaxAbsForce_N} N");
}
註冊步變數
除了預設的步輸出資訊外,您可以使用 RegisterStepVariable(API) 註冊自訂的步變數,用於追蹤特定的計算結果或資料。
註冊的步變數主要用於人類檢視,可透過工件幾何體上的顏色顯示數值分布。搭配 this[string](API) 索引器可實現完整的資料檢查功能:
RegisterStepVariable:註冊變數供介面顯示及輸出MachiningStep[key]:在腳本中讀寫步的自訂資料
RegisterStepVariable
RegisterStepVariable(API) 註冊一個步變數,用於在執行過程中追蹤特定資料。
Note
指令格式
RegisterStepVariable(<鍵值>, <名稱>, <單位>, <格式字串>, <變數函數>);
Tip
指令範例
// 註冊一個計算切削體積的步變數
RegisterStepVariable(
"ChipVolume",
"Chip Volume",
"mm3",
"F2",
(step) => step.ChipVolume_mm3
);
PlayNcFile("NC/file1.nc");
參數說明
<鍵值>: 變數的唯一識別碼<名稱>: 變數的顯示名稱<單位>: 變數的物理單位(可為 null)<格式字串>: 數值格式化字串(可為 null)<變數函數>: 從步計算變數值的函數(可為 null)
Note
註冊的步變數可以在輸出檔案(如 輸出步資料檔案)中使用,並在介面中顯示。
存取步資訊
GetMillingStep
GetMillingStep(API) 取得指定索引的加工步。
Note
指令格式
var step = GetMillingStep(<步索引>);
Tip
指令範例
PlayNcFile("NC/file1.nc");
// 取得第100個步
var step = GetMillingStep(100);
if (step != null)
{
Message($"Step 100: ToolId={step.ToolId}, Feedrate={step.Feedrate_mmdmin}");
}
StepCount
StepCount(API) 取得總步數量。
Note
指令格式
var count = StepCount;
Tip
指令範例
PlayNcFile("NC/file1.nc");
// 取得總步數
var totalSteps = StepCount;
Message($"Total steps: {totalSteps}");
// 遍歷所有步
for (int i = 0; i < StepCount; i++)
{
var step = GetMillingStep(i);
// 處理步...
}