AutoCAD Design Automation工作项打开文件时出错求助
AutoCAD Design Automation 云端WorkItem文档打开失败:获取详细错误信息的方法
我需要通过AutoCAD Design Automation从文件夹打开所有*.dwg文件并从模型空间打印PDF,本地测试正常,但云端WorkItem在调用DocumentManager.Open打开提取文件时失败,仅能看到accoreconsole.exe退出代码1的通用错误提示,无法获知具体故障原因,请问如何获取详细的错误描述?
相关代码片段
var files = Directory.EnumerateFiles(extractZipFolder, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".dwg")); foreach (var file in files) { var openedDocument = AcadApp.DocumentManager.Open(file, false); manager.MdiActiveDocument = openedDocument; var openedDatabase = openedDocument.Database; //Work with opened document... openedDocument.CloseAndDiscard(); }
工作项执行日志
[07/01/2024 15:29:27] Folder "T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\acad_output" has been created. [07/01/2024 15:29:27] Starting work item 80b1dc931698465caca7dd33f3f1038d [07/01/2024 15:29:27] Start download phase. [07/01/2024 15:29:27] Start downloading input: verb - 'Get', url - 'urn:adsk.objects:os.object:wip.dm.prod/a30ef8a9-f959-4e77-bd07-74febaf9e92c.dwg' [07/01/2024 15:29:27] Start downloading input: verb - 'Get', url - 'urn:adsk.objects:os.object:xyicon_bucket/output.json' [07/01/2024 15:29:27] Start downloading input: verb - 'Get', url - 'urn:adsk.objects:os.object:xyicon_bucket/revit_output_.zip' [07/01/2024 15:29:28] End downloading file. Source=urn:adsk.objects:os.object:xyicon_bucket/output.json,LocalFile=T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\inputFile.json,BytesDownloaded=1570,Duration=334ms [07/01/2024 15:29:28] End downloading file. Source=urn:adsk.objects:os.object:xyicon_bucket/revit_output_.zip,LocalFile=T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\acad_input.zip,BytesDownloaded=46107,Duration=330ms [07/01/2024 15:29:28] End downloading file. Source=urn:adsk.objects:os.object:wip.dm.prod/a30ef8a9-f959-4e77-bd07-74febaf9e92c.dwg,LocalFile=T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\Input.dwg,BytesDownloaded=32467,Duration=373ms [07/01/2024 15:29:28] End download phase successfully. [07/01/2024 15:29:28] Start preparing script and command line parameters. [07/01/2024 15:29:28] Command line: [ /i "T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\Input.dwg" "T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\inputFile.json" "T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\acad_input.zip" /al "T:\\Aces\\Applications\\29782f183477c2a1b4b98b6a2426b474.XyiconApp.AutoCADPrintApp[1].package" /s "T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\setting_script.scr"] [07/01/2024 15:29:28] End preparing script and command line parameters. [07/01/2024 15:29:28] Start script phase. [07/01/2024 15:29:28] Start AutoCAD Core Engine standard output dump. [07/01/2024 15:29:28] Redirect stdout (file: T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\tmp\\accc1762). [07/01/2024 15:29:28] AcCoreConsole: StdOutConsoleMode: processed-output: disabled,auto [07/01/2024 15:29:28] AutoCAD Core Engine Console - Copyright 2023 Autodesk, Inc. All rights reserved. (U.61.Z.187) [07/01/2024 15:29:28] Execution Path: [07/01/2024 15:29:28] T:\\Aces\\AcesRoot\\24.3\\coreEngine\\Exe\\accoreconsole.exe [07/01/2024 15:29:28] Current Directory: T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d [07/01/2024 15:29:28] Isolating to regkey=HKEY_CURRENT_USER\\SOFTWARE\\AppDataLow\\Software\\Autodesk\\CoreUser\\WorkItem_80b1dc931698465caca7dd33f3f1038d, userDataFolder=T:\\Aces\\Jobs\\80b1dc931698465caca7dd33f3f1038d\\userdata. [07/01/2024 15:29:28] Version Number: U.61.Z.187 (UNICODE) [07/01/2024 15:29:28] LogFilePath has been set to the working folder. [07/01/2024 15:29:29] Regenerating model. [07/01/2024 15:29:29] AutoCAD menu utilities loaded. [07/01/2024 15:29:29] Command: [07/01/2024 15:29:29] Command: [07/01/2024 15:29:29] Command: [07/01/2024 15:29:29] Command: (command "DWGTOPDF") [07/01/2024 15:29:32] End AutoCAD Core Engine standard output dump. [07/01/2024 15:29:32] Error: Application accoreconsole.exe exits with code 1 which indicates an error. [07/01/2024 15:29:32] End script phase. [07/01/2024 15:29:32] Error: An unexpected error happened during phase CoreEngineExecution of job. [07/01/2024 15:29:32] Job finished with result FailedExecution [07/01/2024 15:29:32] Job Status: { "status": "failedInstructions", "activityId": "XyiconApp.AutoCADPrintAppActivity+dev", "stats": { "timeQueued": "2024-07-01T15:29:27.5198543Z", "timeDownloadStarted": "2024-07-01T15:29:27.6941103Z", "timeInstructionsStarted": "2024-07-01T15:29:28.129703Z", "timeInstructionsEnded": "2024-07-01T15:29:32.5634556Z", "bytesDownloaded": 80144 }, "id": "80b1dc931698465caca7dd33f3f1038d" }
获取详细错误信息的方法
添加代码级异常捕获与日志记录
在处理DWG文件的循环中加入try-catch块,捕获所有异常并写入本地日志文件,同时要将该日志文件配置为WorkItem的输出文件,以便后续下载查看。示例代码如下:foreach (var file in files) { try { var openedDocument = AcadApp.DocumentManager.Open(file, false); manager.MdiActiveDocument = openedDocument; var openedDatabase = openedDocument.Database; //Work with opened document... openedDocument.CloseAndDiscard(); } catch (Exception ex) { string logPath = Path.Combine(Environment.CurrentDirectory, "detailed_error.log"); File.AppendAllText(logPath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 处理文件 {file} 出错: {ex.Message}\n{ex.StackTrace}\n\n"); // 可选:继续处理下一个文件,避免单个文件失败导致整个任务终止 } }启用AutoCAD Core Console的详细日志
在WorkItem的命令行参数中添加/l "acad_detailed.log",强制accoreconsole生成详细操作日志;或者在代码中通过设置系统变量开启日志:AcadApp.SetSystemVariable("LOGFILEMODE", 1); // 开启日志 AcadApp.SetSystemVariable("LOGFILENAME", Path.Combine(Environment.CurrentDirectory, "acad_core.log")); // 指定日志路径查看WorkItem的完整错误流
在Autodesk Platform Services的WorkItem详情页面,检查是否有未显示的标准错误流(stderr)输出,部分错误信息会被定向到这里,而非默认的标准输出(stdout)。本地模拟云端环境调试
使用本地的accoreconsole.exe,按照云端WorkItem的命令行参数和文件结构运行应用,复现错误后直接查看本地生成的日志和错误信息,便于快速定位问题。
内容的提问来源于stack exchange,提问作者SergeySSH
相关产品推荐
相关产品推荐

