1

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

Kev Wilson
  • 470
  • 6
  • 19

2 Answers2

2

This is a summary on what I have discussed with Kev. just for reference in the future.

It is a good practice to verify the workflow of Design Automation by simple scripts. Here is a Postman collection that might help: getpostman.com/collections/e7db377746740e9fa35c to use it, you will need to define the corresponding parameters of the collection.

In Kev's case, the result drawing from design automation was not problematic, the issue was Kev had encoded the drawings to upload to Forge bucket. That's what was going wrong the encoding/decoding was corrupting the file.

Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14
0

What version of AutoCAD do you use to open the resulting drawing? You are using engine version 20.1 which corresponds to AutoCAD 2016. The save command outputs the file in the default format for this version which is 2013. Is it possible that you are using a version prior to AutoCAD 2013 to read the results?

BTW, you can use the SAVEAS command to specify the DWG version you want to output.

user229044
  • 232,980
  • 40
  • 330
  • 338
Albert Szilvasy
  • 461
  • 3
  • 5
  • I'm using the latest version of autoCAD locally, but would that explain the huge file size discrepancy? – Kev Wilson Oct 13 '16 at 17:32
  • Yes it could. Very old dwg files don't use compression so if your input drawing is old then the resulting output file can be substantially smaller. Can you post an input and output drawing that show this problem? – Albert Szilvasy Oct 13 '16 at 18:39
  • Fair enough. I'm not in the office until tomorrow (UK), but I can post them when I'm in. – Kev Wilson Oct 13 '16 at 18:41
  • 1
    Hi Kev, I tried with the http request above with a simple DWG of release 2016. it looks working well at my side. The result DWG can be opened successfully in 2016 and the MText is displayed correctly. If your source DWG is available, I can give it a test at my side. – Xiaodong Liang Oct 14 '16 at 13:39
  • @AlbertSzilvasy Thanks for your suggestions guys, but I'm still having no luck. I have updated my question with links to the input and output files. – Kev Wilson Oct 17 '16 at 10:25
  • @XiaodongLiang Thanks for your suggestions guys, but I'm still having no luck. I have updated my question with links to the input and output files. – Kev Wilson Oct 17 '16 at 10:25
  • 1
    @KevWilson, I used your drawing and tested with my Postman scripts. It can still work well. The result drawing is valid. This is my test video. http://autode.sk/2e3bOTh I firstly put the source drawing to Ali Cloud storage. It does not matter where the drawing is. It is just for a test. You can also access this drawing directly. It is not a signed URL http://forge-test.oss-cn-shanghai.aliyuncs.com/test.dwg I also compared your Activity definition with mine. I did not find a difference. probably you could also try with the drawing which on my Ali cloud storage? – Xiaodong Liang Oct 18 '16 at 04:32
  • 1
    @KevWilson, but when I checked your report on google storage, it looks it has indicated the failure: Error: AutoCAD Core Console failed to finish the script - an unexpected input is encountered. are you sure you tested with the Activity definition you posted at the beginning? I am a bit confused because at the beginning, your report is ''succeeded' but result drawing is invalid, but the data you put on google storage reports the process failed. Then it is not strange to me the result drawing is invalid. – Xiaodong Liang Oct 18 '16 at 04:47
  • @XiaodongLiang My apologies, I had uploaded the wrong log to the g-drive. It was from a previous test. I've re-tried everything this morning using the file you hosted on Ali Cloud but I still get the same results. I have saved the output from each stage to a text file along with the output file and the report.log. please find them here: https://drive.google.com/open?id=0B7GM1RWKWZHGbWVqb2hKd2lEbFU I am going to set up postman and run some tests through that as per your video, hopefully I can see what I am doing differently to you. Thanks again for your help. – Kev Wilson Oct 18 '16 at 09:01
  • 2
    @KevWilson, thanks for clarification. To save your time, I shared the collection of Postman with you: https://www.getpostman.com/collections/e7db377746740e9fa35c . While looking closely at your first post, you uploaded the result to the bucket of Forge? so you actually download the result.dwg from that bucket? If yes, I doubt probably the uploading is problematic. Anyway, the first you could verify is to get the result.dwg directly from the response of WorkItem. – Xiaodong Liang Oct 18 '16 at 13:20
  • @XiaodongLiang, Thank you for sharing your Postman collection that was a huge help. I followed your advice and setup a WorkItem without an output resource and downloaded the resource from s3 and it worked! It looks like the problems are happening during the upload to the bucket. Now I know where to look I can get this solved. You've been a massive help, thank you very much. – Kev Wilson Oct 19 '16 at 08:43
  • @XiaodongLiang, Just to let you know, I have everything working now. I had encoded the drawings to upload to the bucket. That's what was going wrong the encoding/decoding was corrupting the file. Thanks again for all your help. – Kev Wilson Oct 19 '16 at 14:13
  • @KevWilson, I am very glad to know this problem is addressed :) To help more, I posted an answer to summary what we discussed. Could you mark it as a solution if it well tells the context? Thank you! – Xiaodong Liang Oct 21 '16 at 03:21