I've been working with the Design Automation API to run some simple scripts on some drawing files, but my output file is always corrupted and I'm not sure why.
I'm running the following script to add some data to a drawing in a MTEXT
; 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
This script works well when I run it in a local version of autoCAD but when I run it on the Design Automation API the results file is a small un-openable mess!
I am making the activity with the following details
{
"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"
}
When I run this activity on the Design Automation API I get the following response
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'
This is where things get confusing. As you can see above the report has Status => 'Succeeded'
but if we look at the bytes in/out we see
BytesTranferredIn => (int) 59840
BytesTranferredOut => (int) 22702
And when I try to download and open the file autoCAD says it is corrupted, which is no surprise as a lot seems to be missing. I've downloaded the report from the API and again I cannot see any reason why this is failing!
[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\Jobs\694fa87557db46a985a63f6e40c1e681\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\Jobs\694fa87557db46a985a63f6e40c1e681\test.dwg" /s "C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\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\Jobs\694fa87557db46a985a63f6e40c1e681\userdata" /exe "C:\Aces\AcesRoot\20.1\coreEngine\Exe\accoreconsole.exe" /i "C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\test.dwg" /s "C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\script.scr".
[10/13/2016 11:49:42] HostApp = C:\Aces\AcesRoot\20.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\Jobs\694fa87557db46a985a63f6e40c1e681\userdata.
[10/13/2016 11:49:42] Launching sandbox process: [C:\Aces\AcesRoot\20.1\coreEngine\Exe\accoreconsole.exe /i C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\test.dwg /s C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\script.scr /isolate job_694fa87557db46a985a63f6e40c1e681 C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\userdata]
[10/13/2016 11:49:42] Setting TMP to [C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\userdata\temp]
[10/13/2016 11:49:42] Redirect stdout (file: C:\Aces\Jobs\694fa87557db46a985a63f6e40c1e681\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\Jobs\694fa87557db46a985a63f6e40c1e681\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\Jobs\694fa87557db46a985a63f6e40c1e681\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
I've got no idea what's causing these issues when everything seems to point to success. Any help would be great.
If you need any more info please let me know.
======= Update =======
Thanks for your suggestions everyone, I've been out of the office for a few days so not had chance to test your ideas.
I thought over the weekend I may be running autoCad 2017 but I've checked this morning and it's 2016. I tried to run the script again using the 21.0 engine as a test, but the result was almost the same!
I have allowed share access to the g-drive dir where I am taking the file from and I have also uploaded the results.dwg file and the last report there for you guys to have a look at.
You can find them here
I'm sure there is something stupid I am missing