0

I am working on a project where I am required to create multiple revit files, zip them all together and download the zip file as the output in design automation API for Revit.

My project is completely working as expected on my local machine, but when I upload my appbundle and execute my workitem, I get a "failedInstructions" status.

I am not aware whether it is possible to create multiple revit files in design automation API

Following is what I have tried:

This is my workitem json, you see I am passing a json array with sample data for the wall.

 "arguments":{
        "ElementParams":{
            "url":"{'elementdata':[[{'Keys':'Sytème','Value':'Wall_1'},{'Keys':'Thickness','Value':'120.00'},{'Keys':'Length','Value':'2500.00'},{'Keys':'Height','Value':'1200.00'}],[{'Keys':'Sytème','Value':'Wall_2'},{'Keys':'Thickness','Value':'120.00'},{'Keys':'Length','Value':'2500.00'},{'Keys':'Height','Value':'1200.00'}],[{'Keys':'Sytème','Value':'Wall_3'},{'Keys':'Thickness','Value':'120.00'},{'Keys':'Length','Value':'2500.00'},{'Keys':'Height','Value':'1200.00'}],[{'Keys':'Sytème','Value':'Wall_4'},{'Keys':'Thickness','Value':'120.00'},{'Keys':'Length','Value':'2500.00'},{'Keys':'Height','Value':'1200.00'}]]}"
            },

        "resultFamily":{
            "verb":"put",
            "url":"https://storage.googleapis.com/bucketname/RevitObjects.zip?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "headers": {
              "Authorization": "",
              "Content-Type": "application/octet-stream"
            }
        }
    }



In my code, I create a new document in a loop.

Document doc = app.NewProjectDocument(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "DefaultTemplates.rte");



and save and close the current document

SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
doc.SaveAs(Assembly.GetExecutingAssembly().Location) + "\\" + fileName, options);

doc.Close(); //Closing the document

List<string> files = Directory.GetFiles(Assembly.GetExecutingAssembly().Location) + "\\").Where(a => a.Contains(Path.GetFileNameWithoutExtension(fileName)) && a.Split('.').Count() > 2).ToList();
foreach (var fl in files)
{
if (File.Exists(fl))
File.Delete(fl);
}

byte[] filebytes = File.ReadAllBytes(GlobalData.TemplatePath + "\\" + GlobalData.DestinationFile);
GlobalData.FileList.Add(GlobalData.DestinationFile, filebytes);


Here fileName is Wall_1, Wall_2, Wall_3 and Wall_4 which will appear in a loop
Here what I am doing is saving the created revit file example Wall_1
After closing the document, there is a copy of the file created example Wall_1.0001.rvt. I delete all the additional files created and keep one final version and add it to file bytes.

The data added in byte[] filebytes is then used to create a zip file of name "RevitObjects.zip"
After which I delete all the files.

This process works perfect on my local machine, but when I execute the workitem the log created states the following:

[07/03/2019 13:47:38] Error: An unexpected error happened during phase CoreEngineExecution of job.
[07/03/2019 13:47:38] Job finished with result FailedExecution
[07/03/2019 13:47:38] Job Status:
{
  "status": "failedInstructions",

No other error message is stated in the log.

Let me know if multiple revit document creation is possible in design automation api for revit
Are we not allowed to perform delete operation in the working directory.
I tried by creating a folder and performing the same operation mentioned above, but I got an access denied message.
Let me know where I have gone wrong. Also any guidance to achieve the task will be appreciated
Thank you

JPais
  • 115
  • 2
  • 14

2 Answers2

0

First of all, Yes, multiple revit file output is supported by Design Automation system, it's very easy that you just need to set the parameter zip to "true" of your output, and within your plugin, save all your output file to a folder as you named in your output parameter of "localName", please check my blog post at https://forge.autodesk.com/blog/how-generate-dynamic-number-output-design-automation-revit-v3 for all the details.

You are not allowed to access any other folders except the current working folder, you can create subfolder under current working folder and put all your files there.

Hope it helps.

Zhong Wu
  • 1,721
  • 1
  • 8
  • 9
  • Thank you for your reply, but it didn't work, I create a directory under my current working directory using Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\RevitObjects"); I get an error in the log as System.UnauthorizedAccessException: Access to the path 'T:\Aces\Applications\9130ea1858b0af47872ce59a7c8589a0.appName.package\appName.bundle\Contents\RevitObjects' is denied. – JPais Jul 04 '19 at 06:09
  • is there any other method to create a sub folder within the current working directory? – JPais Jul 04 '19 at 06:10
  • I removed the try catch block to check if the log files registers some error, I got the error as request exceeded the allowed limit, Is there a way to increase the Content Length of the input request? – JPais Jul 04 '19 at 11:20
  • Did you try Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\RevitObjects")? This is the current working folder which you can access. And as in my blog, it works as: doc.Export( Directory.GetCurrentDirectory()+ "\\exportedDwgs", "rvt", viewIds, options); – Zhong Wu Jul 04 '19 at 14:10
  • As Zhong mention, I don't expect you will have write access in the folder where your assembly (appBundle) got downloaded. You will need to use the current directory instead. I think the best approach would be to create a sub-folder in the current directory and store all the files you want to zip in there. That way all you have to do to produce a zip output with the desired files is to modify your output argument in your activity to add zip:true and localName: "NameOftheSubFolderYouCreatedInTheCurrentDirectory". This should produce the output zip file you desire. – Jeremy Jul 04 '19 at 15:56
  • Yes, I cannot create a folder in the working directory, what I have done is uploaded the appbundle with an empty folder with the same name as that of my zip file and got the output zip file – JPais Jul 04 '19 at 18:08
  • Thanks Zhong, your solution was helpful, I will mark it as the answer – JPais Jul 04 '19 at 18:09
  • Just a few doubts, will the contents created in the folder be deleted after the execution of the workitem process? and the second doubt is suppose I want to create a zip file of 10 revit files, and the input data passed in the json argument is very large, how can I increase the Content Length of the payload, I am getting an error as content length exceeded. – JPais Jul 04 '19 at 18:13
  • 1. All your input and output files will be deleted after the workitem is done, nothing will remain there. 2. There is a limitation for the content length of the payload, it's 16KB as documented at https://forge.autodesk.com/en/docs/design-automation/v3/developers_guide/quotas/ and i don't think you can modify that, if the length exceeded, make it an input file as normal. – Zhong Wu Jul 05 '19 at 00:54
0

If the json argument is very large, you may provide a "inputParameters.json" as an input file, instead of passing everything in the WorkItem payload

Emma Zhu
  • 220
  • 2
  • 6