设计自动化 API:我的文件已损坏,但一切都指向成功

Design Automation API: My file is being corrupted but everything points to success

我一直在使用设计自动化 API 到 运行 一些绘图文件上的一些简单脚本,但我的输出文件总是损坏,我不确定为什么。

我正在运行使用以下脚本将一些数据添加到 MTEX​​T 中的绘图

; Some setup of variables
;
; Get the co-ords of the bottom right corner
(setq x-coord (car (getvar 'extmax)))
(setq y-coord (cadr (getvar 'extmin)))
; Move the coords away from the drawing a bit
(setq y-coord (- y-coord 5))
; Create multi-line text at bottom right in a 200 x 100 box
-mtext (list x-coord y-coord) h 2 (list (+ x-coord 200) (- y-coord 100)) - - MED data - - 
Project: Project X
End User: TestCorp  
Tag No: P1234567
Version: 1  
Created: 29/09/16
Modified: 29/09/16

(command "_save" "result.dwg")
; end

当我在本地版本的 autoCAD 中 运行 这个脚本运行良好,但是当我在 Design Automation 运行 中 运行 它时,结果文件是一个小的无法打开的文件一团糟!

我正在制作 activity 具有以下详细信息

{
  "HostApplication":"",
  "RequiredEngineVersion":"20.1",
  "Parameters":{
    "InputParameters": [
      {
        "Name":"HostDwg",
        "LocalFileName":"$(HostDwg)"
      }
    ],
    "OutputParameters":[
      {
        "Name":"Result",
        "LocalFileName":"result.dwg"
      }
    ]
  },
  "Instruction":{
    "CommandLineParameters":null,
    "Script":"; Some setup of variables\n;\n; Get the co-ords of the bottom right corner\n(setq x-coord (car (getvar 'extmax)))\n(setq y-coord (cadr (getvar 'extmin)))\n; Move the coords away from the drawing a bit\n(setq y-coord (- y-coord 5))\n; Create multi-line text at bottom right in a 200 x 100 box\n-mtext (list x-coord y-coord) h 2 (list (+ x-coord 200) (- y-coord 100)) - - MED data - - \nProject: Project X\nEnd User: TestCorp\nTag No: P1234567\nVersion: 1\nCreated: 29\/09\/16\nModified: 29\/09\/16\n\n(command \"_save\" \"result.dwg\")\n; end"
  },
  "Version":1,
  "Id":"TagMtextDataAndSave"
}

当我在 Design Automation 运行 activity 上 API 我得到以下响应

ActivityId => 'TagMtextDataAndSave'
Arguments => object(stdClass) {
    InputArguments => [
    (int) 0 => object(stdClass) {
        Resource => 'https://drive.google.com/uc?export=download&id=XXXXXXXXXXXXXXXXXXXXX'
        Name => 'HostDwg'
        Headers => []
        ResourceKind => null
        StorageProvider => 'Generic'
        HttpVerb => null
    }
]
OutputArguments => [
    (int) 0 => object(stdClass) {
        Resource => 'https://developer.api.autodesk.com/oss/v2/buckets/my-persistent-bucket/objects/result.dwg'
        Name => 'Result'
        Headers => [
            (int) 0 => object(stdClass) {
                Name => 'Authorization'
                Value => 'Bearer XXXXXXXXXXXXXXXXX'
            }
        ]
        ResourceKind => null
        StorageProvider => 'Generic'
        HttpVerb => 'PUT'
    }
  ]
}
Status => 'Succeeded'
StatusDetails => object(stdClass) {
    Report => ''
}
AvailabilityZone => null
TimeQueued => '2016-10-13T11:49:40.151Z'
TimeInputTransferStarted => '2016-10-13T11:49:40.085Z'
TimeScriptStarted => '2016-10-13T11:49:42.085Z'
TimeScriptEnded => '2016-10-13T11:49:43.35Z'
TimeOutputTransferEnded => '2016-10-13T11:49:43.741Z'
BytesTranferredIn => (int) 59840
BytesTranferredOut => (int) 22702
Timestamp => '2016-10-13T11:49:43.741Z'
Id => '694fa87557db46a985a63f6e40c1e681'

这就是事情变得混乱的地方。正如您在上面看到的那样,报告有 Status => 'Succeeded',但如果我们查看字节 in/out,我们会看到

BytesTranferredIn => (int) 59840
BytesTranferredOut => (int) 22702

当我尝试下载并打开文件时,autoCAD 说它已损坏,这并不奇怪,因为很多东西似乎都丢失了。我已经从 API 下载了报告,但我还是看不出有任何失败的原因!

[10/13/2016 11:49:40] Starting work item 694fa87557db46a985a63f6e40c1e681
[10/13/2016 11:49:40] Start download phase.
[10/13/2016 11:49:40] Start downloading file https://drive.google.com/uc?export=download&id=XXXXXXXXXXXXXXXXXXXX
[10/13/2016 11:49:41] Redirected, download from https://doc-0s-10-docs.googleusercontent.com/docs/securesc/ha0roXXXXXXXXXXXXXXXXXXXXmbp1/XXXXXXXXXXXXXXXXXXXX/1476352800000/02518323576368124429/*/0B7GM1RWKWZHGdnhMSmRrSDhodDQ?e=download instead.
[10/13/2016 11:49:42] Time spent on downloading from redirected url is 0.1718424 seconds.
[10/13/2016 11:49:42] End downloading file https://drive.google.com/uc?export=download&id=XXXXXXXXXXXXXXXXXXXX. 59840 bytes have been written to C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\test.dwg.
[10/13/2016 11:49:42] End download phase.
[10/13/2016 11:49:42] Start preparing script and command line parameters.
[10/13/2016 11:49:42] Start script content.
[10/13/2016 11:49:42] ; Some setup of variables
;
; Get the co-ords of the bottom right corner
(setq x-coord (car (getvar 'extmax)))
(setq y-coord (cadr (getvar 'extmin)))
; Move the coords away from the drawing a bit
(setq y-coord (- y-coord 5))
; Create multi-line text at bottom right in a 200 x 100 box
-mtext (list x-coord y-coord) h 2 (list (+ x-coord 200) (- y-coord 100)) - - MED data - - 
Project: Project X
End User: TestCorp
Tag No: P1234567
Version: 1
Created: 29/09/16
Modified: 29/09/16

(command "_save" "result.dwg")
; end
[10/13/2016 11:49:42] End script content.
[10/13/2016 11:49:42] Command line: /i "C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\test.dwg" /s "C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\script.scr"
[10/13/2016 11:49:42] End preparing script and command line parameters.
[10/13/2016 11:49:42] Start script phase.
[10/13/2016 11:49:42] ### Command line arguments: /isolate job_694fa87557db46a985a63f6e40c1e681 "C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\userdata" /exe "C:\Aces\AcesRoot.1\coreEngine\Exe\accoreconsole.exe"  /i "C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\test.dwg" /s "C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\script.scr".
[10/13/2016 11:49:42] HostApp = C:\Aces\AcesRoot.1\coreEngine\Exe\sandboxer.exe.
[10/13/2016 11:49:42] Start AutoCAD Core application output.
[10/13/2016 11:49:42] Redirect stdout (file: C:\Users\ACESWO~1\AppData\Local\Temp\accc40643).
[10/13/2016 11:49:42] Isolating to userId=job_694fa87557db46a985a63f6e40c1e681, userDataFolder=C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\userdata.
[10/13/2016 11:49:42] Launching sandbox process: [C:\Aces\AcesRoot.1\coreEngine\Exe\accoreconsole.exe /i C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\test.dwg /s C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\script.scr  /isolate job_694fa87557db46a985a63f6e40c1e681 C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\userdata]
[10/13/2016 11:49:42] Setting TMP to [C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\userdata\temp]
[10/13/2016 11:49:42] Redirect stdout (file: C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\userdata\temp\accc24922).
[10/13/2016 11:49:42] AutoCAD Core Engine Console - Copyright 2015 Autodesk, Inc.  All rights reserved. (M.49.Z.1)
[10/13/2016 11:49:42] Running at low integrity.
[10/13/2016 11:49:42] Substituting [simplex.shx] for [G415L_A3.SHX].
[10/13/2016 11:49:42] Regenerating model.
[10/13/2016 11:49:42] Command:
[10/13/2016 11:49:42] Command:
[10/13/2016 11:49:42] Command:
[10/13/2016 11:49:42] Command: (setq x-coord (car (getvar 'extmax)))
[10/13/2016 11:49:42] 50.2149
[10/13/2016 11:49:42] Command: (setq y-coord (cadr (getvar 'extmin)))
[10/13/2016 11:49:42] 7.46976
[10/13/2016 11:49:42] Command: (setq y-coord (- y-coord 5))
[10/13/2016 11:49:42] 2.46976
[10/13/2016 11:49:43] Command: -mtext
[10/13/2016 11:49:43] Current text style:  "Standard"  Text height:  0.2000  Annotative:  No
[10/13/2016 11:49:43] Specify first corner: (list x-coord y-coord) (50.2149 2.46976)
[10/13/2016 11:49:43] Specify opposite corner or [Height/Justify/Line spacing/Rotation/Style/Width/Columns]: h
[10/13/2016 11:49:43] Specify height <0.2000>: 2
[10/13/2016 11:49:43] Specify opposite corner or [Height/Justify/Line spacing/Rotation/Style/Width/Columns]: (list (+ x-coord 200) (- y-coord 100)) (250.215 -97.5302)
[10/13/2016 11:49:43] MText: - - MED data - -
[10/13/2016 11:49:43] MText: Project: Project X
[10/13/2016 11:49:43] MText: End User: TestCorp
[10/13/2016 11:49:43] MText: Tag No: P1234567
[10/13/2016 11:49:43] MText: Version: 1
[10/13/2016 11:49:43] MText: Created: 29/09/16
[10/13/2016 11:49:43] MText: Modified: 29/09/16
[10/13/2016 11:49:43] MText:
[10/13/2016 11:49:43] Command: (command "_save" "result.dwg")
[10/13/2016 11:49:43] _save Save drawing as <C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\test.dwg>: result.dwg
[10/13/2016 11:49:43] Command: nil
[10/13/2016 11:49:43] Command: _quit
[10/13/2016 11:49:43] End AutoCAD Core Console output
[10/13/2016 11:49:43] End script phase.
[10/13/2016 11:49:43] Start upload phase.
[10/13/2016 11:49:43] Uploading C:\Aces\Jobs4fa87557db46a985a63f6e40c1e681\result.dwg to https://developer.api.autodesk.com/oss/v2/buckets/my-persistent-bucket/objects/result.dwg.
[10/13/2016 11:49:43] End upload phase.
[10/13/2016 11:49:43] Job finished with result Succeeded

当一切似乎都指向成功时,我不知道是什么导致了这些问题。任何帮助都会很棒。

如果您需要更多信息,请告诉我。

                       ======= Update =======

感谢大家的建议,我已经离开办公室几天了,所以没有机会测试你的想法。

我想周末我可能会 运行ning autoCad 2017,但我今天早上检查过它是 2016 年。我尝试使用 21.0 引擎再次 运行 脚本作为测试, 但结果几乎一样!

我已允许共享访问我从中获取文件的 g-drive 目录,我还上传了 results.dwg 文件和最后一份报告供你们查看。

你可以找到它们here

我确定我遗漏了一些愚蠢的东西

您使用什么版本的 AutoCAD 打开生成的图形?您使用的引擎版本为 20.1,对应 AutoCAD 2016。保存命令以该版本(即 2013)的默认格式输出文件。是否有可能您使用的是 AutoCAD 2013 之前的版本来读取结果?

顺便说一句,您可以使用SAVEAS命令指定您要输出的DWG版本。

这是我与 Kev 讨论的内容的总结。仅供以后参考。

通过简单的脚本来验证设计自动化的工作流程是一种很好的做法。这是一个可能有帮助的 Postman 集合: getpostman.com/collections/e7db377746740e9fa35c 要使用它,您需要定义集合的相应参数。

在 Kev 的案例中,设计自动化的结果图没有问题,问题是 Kev 对图纸进行了编码以上传到 Forge 存储桶。这就是问题所在 encoding/decoding 正在损坏文件。