How to run the export method asynchronously

How to run the export method asynchronously

smutnyENWWU
Explorer Explorer
414 Views
1 Reply
Message 1 of 2

How to run the export method asynchronously

smutnyENWWU
Explorer
Explorer

Hello,

I am doing Revit plugin which contains method that exports document to IFC. The thing I don't like is that the export takes several seconds and from my point of view it can be little bit confusing for users to find out if the file is actually exporting (I was confused as well for the first time), because Revit shows only little note in bottom left corner which can be very easily missed. So I wanted to run the export method asynchronously and show WPF window, which would say to user, that file is exporting in the mean-time. But I haven't found any way to achieve this.

Here is what I've already tried:

I have standard execute method.

 

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            UIApplication uiapp = commandData.Application;
            Document doc = uiapp.ActiveUIDocument.Document;

 

Then I would like to run export and show the WPF window (Upload) during the export saying something like "Exporting in progress...".

 

            Transaction trans = new Transaction(doc);
            trans.Start("Lab");
            ThreadStart starterOne = delegate { ExportParallel(ref doc, ref trans, folderPath, file); };
            Thread thread = new Thread(starterOne);
            thread.Start();


            Upload uploadTest = new Upload();
            uploadTest.ShowDialog();

 

   And here is my ExportParallel method

 

        public void ExportParallel(ref Document doc, ref Transaction trans, string folderPath, string file)
        {
            doc.Export(folderPath, file, new IFCExportOptions());
            trans.Commit();
        }

 

Does anyone have any idea, how can I achieve this? I am still getting error "Autodesk.Revit.Exceptions.InternalException: 'Restriction not handled" on the doc.Export() line...

Thank you very much

Have a great day

Jan

 

0 Likes
Accepted solutions (1)
415 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni
Accepted solution

Revit and its API is single threaded:

  

http://thebuildingcoder.typepad.com/blog/2011/06/no-multithreading-in-revit.html

 

As long as it is busy exporting, it will be blocked.

 

You can certainly disconnect your WPF UI from Revit to let the user do other things.

 

However, it is impossible to do other things with Revit as long as it is busy with its job.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open