Automatically export all sheets as Autocad files

Automatically export all sheets as Autocad files

klaus.kapeller
Participant Participant
2,021 Views
5 Replies
Message 1 of 6

Automatically export all sheets as Autocad files

klaus.kapeller
Participant
Participant

Hi,

 

I just found some examples on writing ADDINs for Revit - but none how to automate Revit without user interaction.

 

I want to automate the following for a batch export:

  • Start Revit - if not started
  • Open a Revit file
  • Export all Sheets as Autocad files to a defined folder
  • Close Revit

Is there a way to do this without any interaction of any user?

 

Thanks a lot

Klaus

 

0 Likes
Accepted solutions (2)
2,022 Views
5 Replies
Replies (5)
Message 2 of 6

recepagah12
Advocate
Advocate
Accepted solution

I think your best deal is FORGE DA4R(Design Automation for Revit). It is really good for tasks like that and you don't even have to own Revit license. 

But if you want to have a desktop app, you can create a IExternalDBApplication Interface that implements, every time you open a new document, it exports sheet then you can subscribe it manually once and for all.

In another Windows Desktop Console Application, you can implement open revit file then close it so on.

I wrote some code for this hope that helps. Need some polishing though.

 

This is IExternalDBApplication Interface

public class sheetExporterDB : IExternalDBApplication
    {
        public ExternalDBApplicationResult OnShutdown(ControlledApplication application)
        {
            application.DocumentOpened -= Application_DocumentOpened;
            return ExternalDBApplicationResult.Succeeded;
        }

        public ExternalDBApplicationResult OnStartup(ControlledApplication application)
        {
            application.DocumentOpened += Application_DocumentOpened;
            return ExternalDBApplicationResult.Succeeded;
        }

        private void Application_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            Document doc = e.Document;

            using (Transaction t = new Transaction(doc))
            {
                // Start the transaction
                t.Start("Export Sheets DWG");
                try
                {
                    var viewSheets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>();

                    // create DWG export options
                    DWGExportOptions dwgOptions = new DWGExportOptions();
                    dwgOptions.MergedViews = true;
                    dwgOptions.SharedCoords = true;
                    dwgOptions.FileVersion = ACADVersion.R2013;

                    List<ElementId> views = new List<ElementId>();

                    foreach (var sheet in viewSheets)
                    {
                        if (!sheet.IsPlaceholder)
                        {
                            views.Add(sheet.Id);
                        }
                    }
                    doc.Export(@"D:\sheetExporterLocation","TEST.dwg", views, dwgOptions);
                }
                catch (Exception ex)
                {
                }
                // Commit the transaction
                t.Commit();
            }
        }
    }

 

This is the console app

static void Main(string[] args)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo()
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                // Project Location
                FileName = @"D:\forgeWindowTest.rvt"
            };
            p.StartInfo = psi;
            p.Start();
        }

 

Hope that helps,

Recep.

0 Likes
Message 3 of 6

recepagah12
Advocate
Advocate

In IExternalDBApplication, if you add doc.Close();

It will automatically close the document after processing. Also, I just tested with some RVT files and it works well.

If you have any problem please ask.

0 Likes
Message 4 of 6

klaus.kapeller
Participant
Participant
Accepted solution

Thanks and sorry for do not give any replies.

But due to corona and holydays i was in short work and had no time to proceed with that topic.

 

Hopefully I will have time to work on t the next month...

 

I will give you an answer

0 Likes
Message 5 of 6

klaus.kapeller
Participant
Participant

Hi and thanks a lot....it works really fine.

 

I added an addin manifest in C:\ProgramData\Autodesk\Revit\Addins\2019\MyFirstRevitPlugin.addin:

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<Name>Export DWGs</Name>
<Assembly>D:\data\SourceCodes\dotNET\Revit\FirstPlugIn\FirstRevit\FirstRevit\bin\Debug\MyFirstRevitPlugin.dll</Assembly>
<AddInId>78BD1446-1817-4842-8075-591B0424ACAB</AddInId>
<FullClassName>MyFirstRevitPlugin.Application_DocumentOpened</FullClassName>
<VendorId></VendorId>
<VendorDescription></VendorDescription>
</AddIn>
</RevitAddIns>

 

and it worked fine as designed.

Now I have to clarify the process with the engineers and do the implementation in our process...

 

Thanks

Klaus

 

 

0 Likes
Message 6 of 6

recepagah12
Advocate
Advocate

Hi Klaus,

Firstly, thanks for accepting my answer as a solution.

I implemented this code to Revit DA4R (Design Automation For Revit) and it now works in the cloud.

Here is the link Sheet Exporter on Forge 

You can try it, just select files from your computer than in the left panel download links will appear. 

Multiple file selection works.

0 Likes