diff --git a/src/Core/Services/SectionBoxBatchDetector.cs b/src/Core/Services/SectionBoxBatchDetector.cs index 8289071..31fbf01 100644 --- a/src/Core/Services/SectionBoxBatchDetector.cs +++ b/src/Core/Services/SectionBoxBatchDetector.cs @@ -215,6 +215,27 @@ namespace NavisworksTransport.Core.Services } result.LocalModelPath = localModelPath; + // 启动副实例前文件校验(NW 加载失败会弹原生错误窗口,插件无法拦截): + // 1) 文件存在且非空;2) 未被其他进程占用(残留副实例可能仍持有导出文件) + var exportFileInfo = new FileInfo(localModelPath); + if (!exportFileInfo.Exists || exportFileInfo.Length == 0) + { + result.ErrorMessage = $"导出模型文件无效(不存在或为空): {localModelPath}"; + return result; + } + + try + { + using (var probe = new FileStream(localModelPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) + { + } + } + catch (IOException) + { + result.ErrorMessage = $"导出模型文件被占用(可能有残留副实例进程未退出),请检查残留 Roamer 进程后重试: {localModelPath}"; + return result; + } + // 3. 导出路径文件(JSON,副实例导入用) new PathDataManager().ExportToJson(new List { route }, routeFilePath);