1

I'm trying to send some information in JSON format along with a workitem. The idea is to create a json file called "params.json" in the working folder where the workitem is executed. The problem is the JSON file is not found.

I have this activity:

{
    "commandLine": [
        "$(engine.path)\\\\revitcoreconsole.exe /i \"$(args[rvtFile].path)\" /al \"$(appbundles[ExportPdfApp].path)\""
    ],
    "parameters": {
        "rvtFile": {
            "verb": "get",
            "description": "Input Revit model",
            "required": true,
            "localName": "$(rvtFile)"
        },
        "params": {
            "verb": "get",
            "description": "Parameters",
            "localName": "params.json"
        },
        "result": {
            "verb": "post",
            "description": "PDF Result",
            "localName": "result.pdf"
        }
    },
    "id": "##########",
    "engine": "Autodesk.Revit+2022",
    "appbundles": [
        "##########"
    ],
    "settings": {},
    "version": 4
}

I'm creating a workitem whit this code:

public static class ExportPdfSheetsWorkItem
    {
        public static async Task<string> Create(string revitFileUrl, string parameters)
        {
            string apiUrl = "https://developer.api.autodesk.com/da/us-east/v3/workitems";
            string accessToken = Configuration.Default.AccessToken;

            string activityId = $"###################";
            string resultUrl = "....../api/forge/callback/pdf/$(workitem.id)";
            string progressUrl = "...../api/forge/callback/pdfprogress/$(workitem.id)";

            var data = new Dictionary<string, object>();
            data.Add("activityId", activityId);

            var arguments = new Dictionary<string, object>();
            arguments.Add(
                "rvtFile",
                new Dictionary<string, object>()
                {
                    ["localName"] = "$(rvtFile)",
                    ["url"] = revitFileUrl,
                    ["verb"] = "get",
                    ["headers"] = new Dictionary<string, string>()
                    {
                        ["Content-Type"] = "application/json",
                        ["Authorization"] = $"Bearer {accessToken}"
                    }
                }
             );
            arguments.Add(
                "onProgress",
                new Dictionary<string, object>()
                {
                    ["url"] = progressUrl,
                    ["verb"] = "post",
                }
             );
            arguments.Add(
                "params",
                new Dictionary<string, object>()
                {
                    ["localName"] = "params.json",
                    // Parameters is a json string
                    ["url"] = $"data:application/json,{parameters}"
                }
             );
            arguments.Add(
                "result",
                new Dictionary<string, object>()
                {
                    ["localName"] = "result.pdf",
                    ["url"] = resultUrl,
                    ["verb"] = "post",
                    ["headers"] = new Dictionary<string, string>()
                    {
                        ["Content-Type"] = "application/pdf",
                    }
                }
             );
            data.Add("arguments", arguments);

            string jsonString = JsonConvert.SerializeObject(data);

            using (var httpClient = new HttpClient())
            {
                var contentType = new MediaTypeWithQualityHeaderValue("application/json");
                httpClient.DefaultRequestHeaders.Accept.Add(contentType);

                httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Auth.TwoToken}");

                var content = new StringContent(jsonString, Encoding.UTF8, "application/json");

                var response = await httpClient.PostAsync(apiUrl, content);

                using (var responseStream = response.Content.ReadAsStream())
                {
                    // Read the response data
                    using (var reader = new System.IO.StreamReader(responseStream))
                    {
                        string responseData = reader.ReadToEnd();
                        Console.WriteLine(responseData);
                    }
                }

                if (response.IsSuccessStatusCode)
                {
                    string responseContent = await response.Content.ReadAsStringAsync();

                    Dictionary<string, object> jsonData = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseContent);
                    return jsonData["id"].ToString();
                }
                else
                {
                    return null;
                }
            }
        }
    }
}

The code where I read the json file in the a--bundle is this line:

JsonParser parser = new JsonParser("params.json");

And I'm getting this error on the workitem:

[07/07/2023 01:55:43] Job information:
"CommandLine":[
  "$(engine.path)\\\\revitcoreconsole.exe /i \"$(args[rvtFile].path)\" /al \"$(appbundles[ExportPdfApp].path)\""
]
"Settings":{
  "dasOpenNetwork": {
    "value": "true",
    "isEnvironmentVariable": true
  }
}
"Id":"#####"
"ActivityId":"######"
"Engine.Id":"Autodesk.Revit_2022!111"
"Apps": [
"App.Id":"H2T2ElrwMLlyouCRWb09bXHWJanAz0fW.ExportPdfApp!1"
]
"BoundArguments":{
  "rvtFile": {
    "localName": "$(rvtFile)",
    "url": "https://developer.api.autodesk.com/Masked:6LShKcy6UElH/a8KhqtVS2N2sYw=",
    "headers": {
      "Content-Type": "application/json",
      "Authorization": "Masked:vJ83qYiQWiDkK3hWxCiHcz27UPQ="
    }
  },
  "params": {
    "localName": "params.json",
    "url": "data:application/json,{'pdf_options':{'AlwaysUseRaster':false,'ColorDepth':0,'ExportQuality':0,'HideCropBoundaries':true,'HideReferencePlane':true,'HideScopeBoxes':true,'HideUnreferencedViewTags':true,'MaskCoincidentLines':true,'PaperFormat':0,'PaperOrientation':2,'RasterQuality':0,'ReplaceHalftoneWithThinLines':false},'sets':['adsk 360']}",
    "verb": "put"
  },
  "result": {
    "localName": "result.pdf",
    "url": "http://a76ef21391cb-3916732089906226749.ngrok-free.app/Masked:VJJk/NuXPGHB2EJtQ+H7TItdx00=",
    "headers": {
      "Content-Type": "application/pdf"
    },
    "verb": "post"
  },
  "onProgress": {
    "ondemand": true,
    "optional": true,
    "url": "http://a76ef21391cb-3916732089906226749.ngrok-free.app/Masked:atQBYqzBqp9A5QhD6Q/8oQg+XRk=",
    "verb": "post"
  }
}
"Quotas":{
  "limitProcessingTimeSec": 10800,
  "limitTotalUncompressedAppsSizeInMB": 5000
}
[07/07/2023 01:55:43] Starting work item ebf2607e75a24d6e81b2243c963ce1b6
[07/07/2023 01:55:43] Start download phase.
[07/07/2023 01:55:43] Start downloading input: verb - 'GET', url - 'https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/bcc07c0f-e99f-48cd-9b9b-818367a59b34.rvt?scopes=b360project.f378332d-e6f4-4e7f-a9ec-44ec4fa837b4,O2tenant.5166051'
[07/07/2023 01:55:44] End downloading file. Source=https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/bcc07c0f-e99f-48cd-9b9b-818367a59b34.rvt?scopes=b360project.f378332d-e6f4-4e7f-a9ec-44ec4fa837b4,O2tenant.5166051,LocalFile=T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\4c8d3d9b-58ca-4264-889b-a1f61c0e1f51.rvt,BytesDownloaded=18739200,Duration=1040ms
[07/07/2023 01:55:44] End download phase successfully.
[07/07/2023 01:55:44] Start preparing script and command line parameters.
[07/07/2023 01:55:44] Command line: [ /i "T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\4c8d3d9b-58ca-4264-889b-a1f61c0e1f51.rvt" /al "T:\Aces\Applications\c32de414174706f8a2feed2d2076ef07.H2T2ElrwMLlyouCRWb09bXHWJanAz0fW.ExportPdfApp[1].package"]
[07/07/2023 01:55:44] End preparing script and command line parameters.
[07/07/2023 01:55:44] Start script phase.
[07/07/2023 01:55:44] Start Revit Core Engine standard output dump.
[07/07/2023 01:55:44] ====== Revit is running: revitcoreconsole ======
[07/07/2023 01:55:44] Current Exe path: T:\Aces\AcesRoot\22.0\coreEngine\Exe\revitcoreconsole.exe
[07/07/2023 01:55:44] Echoing command line args:
[07/07/2023 01:55:44]   0:/i
[07/07/2023 01:55:44]   1:T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\4c8d3d9b-58ca-4264-889b-a1f61c0e1f51.rvt
[07/07/2023 01:55:44]   2:/al
[07/07/2023 01:55:44]   3:T:\Aces\Applications\c32de414174706f8a2feed2d2076ef07.H2T2ElrwMLlyouCRWb09bXHWJanAz0fW.ExportPdfApp[1].package
[07/07/2023 01:55:44]   4:/isolate
[07/07/2023 01:55:44]   5:HKEY_CURRENT_USER\SOFTWARE\AppDataLow\Software\Autodesk\CoreUser\WorkItem_ebf2607e75a24d6e81b2243c963ce1b6
[07/07/2023 01:55:44]   6:T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\userdata
[07/07/2023 01:55:44] Selected Revit\RCE install Path: (from app.config)
[07/07/2023 01:55:44] Resolving location of Revit/RevitCoreEngine installation...
[07/07/2023 01:55:44] Loading RCE ....
[07/07/2023 01:55:48] Running user application....
[07/07/2023 01:55:49] Found an addIn for registration: ExportPdf.addin
[07/07/2023 01:55:49] Language not specified, using English-United States(ENU) as default.
[07/07/2023 01:55:52] Get RCE: (VersionBuild) 22.1.40.31 (VersionNumber) 2022 (SubVersionNumber) 2022.1.4
[07/07/2023 01:55:59] System.IO.FileNotFoundException: Could not find file 'T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\params.json'.
[07/07/2023 01:55:59] File name: 'T:\Aces\Jobs\ebf2607e75a24d6e81b2243c963ce1b6\params.json'
[07/07/2023 01:55:59]    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
[07/07/2023 01:55:59]    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
[07/07/2023 01:55:59]    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
[07/07/2023 01:55:59]    at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
[07/07/2023 01:55:59]    at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
[07/07/2023 01:55:59]    at ExportPdf.JsonParser..ctor(String jsonPath)
[07/07/2023 01:55:59]    at ExportPdf.ExportPdfApp.ExportToPdf(DesignAutomationData data)
[07/07/2023 01:55:59]    at ExportPdf.ExportPdfApp.HandleDesignAutomationReadyEvent(Object sender, DesignAutomationReadyEventArgs e)
[07/07/2023 01:55:59]    at DesignAutomationFramework.DesignAutomationBridge.RaiseDesignAutomationReadyEvent(DesignAutomationReadyEventArgs e)
[07/07/2023 01:55:59]    at RevitCoreEngineTest.RceConsoleApplication.Program.UserMain(CommandLineArgs cl)
[07/07/2023 01:56:05] RESULT: Failure - Result of running user app is failure
[07/07/2023 01:56:05] Finished running.  Process will return: TestError
[07/07/2023 01:56:05] ====== Revit finished running: revitcoreconsole ======
[07/07/2023 01:56:07] End Revit Core Engine standard output dump.
[07/07/2023 01:56:07] Error: Application revitcoreconsole.exe exits with code 4 which indicates an error.
[07/07/2023 01:56:07] End script phase.
[07/07/2023 01:56:07] Error: An unexpected error happened during phase CoreEngineExecution of job.
[07/07/2023 01:56:07] Job finished with result FailedExecution
[07/07/2023 01:56:07] Job Status:
{
  "status": "failedInstructions",
  "reportUrl": "https://dasprod-store.s3.amazonaws.com/workItem/KmNrPgjxx05IguTsq7jFWZ8bAAGk2fUH/ebf2607e75a24d6e81b2243c963ce1b6/report.txt?X-Amz-Expires=48600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENr%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJHMEUCIET6p4JuMmMMymu%2BOd0Ju6s2cAE2oSuRc5IJzh6gSrB9AiEAmSU%2FDfuSszs4uuh9WvMOpky1jUb0jQrHGjqGK1CEcHMqgAMIUxADGgwyMjA0NzMxNTIzMTAiDB69holtOziyUU6afCrdAk31T9f0SKGQ2eKP2G9MFtllzCD00SYdMaxvRrsuIrQNZ312Bvaoi%2BZMbP0ZiV5kI7hfTiVTm7yJl3yx9BOEbg77EcoVaI5w3mX342kqA2YtNKCcC1kock4Y37%2Bfzs3b7g2n3H8giMXxANSYQ1nP5W%2FFVPFIN%2FUUW2%2BtPLm0oGCZM%2Fl63KLgYrCfzKPS8NFjUs5icsMcQMPRs5qpoMx5TqIy2%2BqtGE98uuiAZ3jFHT0qbdVhw5NudUdYeaUacflV%2FvmwbMDM1BINlSMSzZnDWbuww3f0OG%2BP%2F4koI3dnEa6yOzK8keR3m51OUjyGcgb%2FgKGME04L%2FajL9S0pEk0GDPnHtIged3GbaYvncCHdpWMBvCe0cl1sIGrlYX%2FK%2BzjT79756TgzBStNYPSbJpLrQ0clxAmadeez3RWix7BEawlkw6K%2F0ZHFU%2FMc90TViFbuiEBGC2ufgpI32gApMosw%2B9adpQY6ngHRCIaGW4iD2odAcbJ7idIlnv6%2FwfD6MnWbz3DzjsnrSjrKnXLFQpIMpdgox94KIFSk7r%2Bd6bnADUKPhFJZoZyXGf25SU40R2dmOt%2FVWxenhCnyikBus9dE6y%2B7Yhxse7wcNB0NhExTKly8nJPgINKfYLYpTfHozTAhylV2UStq09bhwq0Yiqxyg0g%2FUrMuKzCKDMWdmNl%2FNZSF6YEX6g%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIATGVJZKM3JVQDGFFD/20230707/us-east-1/s3/aws4_request&X-Amz-Date=20230707T015542Z&X-Amz-SignedHeaders=host&X-Amz-Signature=675091b3784e3f9b25c70fb877b25ea249bbfb10d8b46494c5f9ed999004b400",
  "stats": {
    "timeQueued": "2023-07-07T01:55:42.7432678Z",
    "timeDownloadStarted": "2023-07-07T01:55:43.016541Z",
    "timeInstructionsStarted": "2023-07-07T01:55:44.1383357Z",
    "timeInstructionsEnded": "2023-07-07T01:56:07.1617745Z",
    "bytesDownloaded": 18739200
  },
  "id": "ebf2607e75a24d6e81b2243c963ce1b6"
}
Eduardo
  • 687
  • 1
  • 6
  • 24
  • Could you share your entire report log or workitem id? I am looking for a line like this in the report: `[07/07/2023 03:41:18] Embedded resource [{'walls': true, 'floors': true, 'doors': true, 'windows': true}] is saved as a file in 'Unicode' at: 'T:\Aces\Jobs\e43053ea8e414c718b4c3632729809e6\CountItParams.json'`. – Rahul Bhobe Jul 07 '23 at 13:10
  • @RahulBhobe Sure! I just updated my question – Eduardo Jul 07 '23 at 13:13
  • See at the top of the report log (`Job Information`). Why is the `BoundArguments.params.verb` == `put`? Should be `get` to be a download argument. Could you check your activity definition again? – Rahul Bhobe Jul 07 '23 at 13:22
  • @RahulBhobe that param should be "get" in the activity definition? – Eduardo Jul 07 '23 at 13:23
  • Yes, `get` means download argument. – Rahul Bhobe Jul 07 '23 at 13:24
  • @RahulBhobe That solved the issue. Thanks! Do you want to post the answer to mark it as a solution? – Eduardo Jul 07 '23 at 13:32
  • I am writing one. – Rahul Bhobe Jul 07 '23 at 13:33

1 Answers1

1

The Job Information at the top of the report log indicates param is an output argument because it has a verb = put. See here:

[07/07/2023 01:55:43] Job information:
"BoundArguments":{
  .
  .
  "params": {
    "localName": "params.json",
    "url": "data:application/json,{'pdf_options':{'AlwaysUseRaster':false,'ColorDepth':0,'ExportQuality':0,'HideCropBoundaries':true,'HideReferencePlane':true,'HideScopeBoxes':true,'HideUnreferencedViewTags':true,'MaskCoincidentLines':true,'PaperFormat':0,'PaperOrientation':2,'RasterQuality':0,'ReplaceHalftoneWithThinLines':false},'sets':['adsk 360']}",
    "verb": "put"
  },

This seems to be contradiction from your activity definition you posted in the description. Is that the correct definition? I'd first check the activity definition and ensure that it is indeed verb = get.

The verbs can also be changed at the time you post a workitem. In your case, you do not seem to be explicitly setting any verb for your argument param, in which case it will use the verb you set in the activity.

Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32