跳轉到

ShellProgress

什麼是 ShellProgress?

ShellProgress(ShellProgress (API))是訊息主體物件,管理 HiNC 腳本工作階段中所產生的所有訊息。它是記錄、過濾與匯出診斷資訊的中央樞紐。

Note

此訊息主體先前名為 SessionProgress(更早是 SessionMessageHost),這些舊名皆已由 ShellProgress 取代。


訊息類型

HiNC 提供四種訊息類型,各有不同嚴重程度與典型顯示行為:

類型 命令 說明 典型顯示
Message Message (API) 一般資訊訊息 訊息面板
ProgressMessage ProgressMessage (API) 進度相關狀態更新 進度條/狀態區
WarningMessage WarningMessage (API) 警告(不中斷執行) 訊息面板(黃色)
ErrorMessage ErrorMessage (API) 錯誤(可能影響執行流程) 訊息面板(紅色)

使用範例

Message("Starting simulation");
ProgressMessage("Loading workpiece...");
WarningMessage("No cutting engagement detected in this segment");
ErrorMessage("Workpiece does not exist");

訊息標籤

訊息可加上標籤以利過濾。標準標籤包含 "Error" 與 "Warning"。匯出訊息時可依一或多個標籤過濾。


顯示訊息

所有訊息會自動記錄於工作階段訊息主體,並顯示於 HiNC UI 的 訊息面板。ProgressMessage 另外會更新 進度條。

存取訊息主體

var messageHost = ShellProgress;

匯出訊息

AppendMessagesToFile (API) 將訊息寫入文字檔,可選擇依標籤過濾:

// 匯出所有訊息
AppendMessagesToFile("Output/messages.txt");

// 僅匯出錯誤與警告
AppendMessagesToFile("Output/errors.txt", "Error", "Warning");

Tip

仿真結束後匯出訊息,以建立可長期保存的日誌供除錯或報告之用。


常見模式

仿真進度日誌

Message("Simulation started");
PlayNcFile("NC/file1.nc");
Message($"Simulation complete. Total steps: {StepCount}");
AppendMessagesToFile("Output/log.txt");

條件式警告

if (StepCount == 0)
{
    WarningMessage("No steps were executed");
}

錯誤防護

if (Workpiece == null)
{
    ErrorMessage("Workpiece does not exist");
    return;
}

透過事件做步級日誌

SessionStepBuilt += (preStep, curStep) => {
    if (curStep != null)
        Message($"Step {curStep.StepIndex}: ToolId={curStep.ToolId}");
};
PlayNcFile("NC/file1.nc");

選取步時的日誌

MachiningStepSelected += (step) => {
    if (step != null && step.ToolId == 1)
        ProgressMessage($"Tool 1 step selected at line {step.LineNo}");
};

訊息生命週期

  1. 訊息於腳本執行期間,透過四個訊息命令產生
  2. 所有訊息皆存於 ShellProgress 主體物件
  3. 訊息會持續存在,直到運行時被重置——不論是呼叫 ResetRuntime(),還是按下播放器的「重置」,兩者執行的是同一個清除動作
  4. ResetRuntime() 會把已記錄的訊息連同步與網格化的工件一起清除——這些訊息若還要用,請先以 AppendMessagesToFile 匯出。掛在工作階段事件上的處理器不會被它移除;它們要等工作階段結束、也就是播放器「重置」時才會移除
  5. 可隨時使用 AppendMessagesToFile 匯出訊息

延伸閱讀

  • 腳本命令 — 腳本命令基礎
  • SessionShell — SessionShell 命令速查
  • 基礎仿真 — 在仿真流程中使用訊息
  • 訊息管理 — HiNc 應用層的三條訊息通道;本頁這個工作階段層級的訊息主體是它們的一個面向(英文,未鏡像)