Exemple #1
0
 /// <summary>
 /// Returns a list of all predefined dwg export options.
 /// </summary>
 /// <returns></returns>
 public static string[] DWGExportOptions()
 {
     return(ExportDWGSettings.ListNames(DocumentManager.Instance.CurrentDBDocument).ToArray());
 }
Exemple #2
0
        private bool ExportDWG(DesignAutomationData data)
        {
            if (data == null)
            {
                return(false);
            }

            Application app = data.RevitApp;

            if (app == null)
            {
                return(false);
            }

            string modelPath = data.FilePath;

            if (string.IsNullOrWhiteSpace(modelPath))
            {
                return(false);
            }

            var doc = data.RevitDoc;

            if (doc == null)
            {
                return(false);
            }

            using (var collector = new FilteredElementCollector(doc))
            {
                LogTrace("Collecting sheets...");

//#if CLOUD
//                var exportPath = Path.Combine(Directory.GetCurrentDirectory(), "exported");
//#else
//                var exportPath = Path.Combine(Path.GetDirectoryName(modelPath), "exported");
//#endif
                var exportPath = Path.Combine(Directory.GetCurrentDirectory(), "exported");
                if (!Directory.Exists(exportPath))
                {
                    try
                    {
                        Directory.CreateDirectory(exportPath);
                    }
                    catch (Exception ex)
                    {
                        this.PrintError(ex);
                        return(false);
                    }
                }

                LogTrace(string.Format("Export Path: {0}", exportPath));

                var sheetIds = collector.WhereElementIsNotElementType()
                               .OfClass(typeof(ViewSheet))
                               .ToElementIds();

                if (sheetIds == null || sheetIds.Count <= 0)
                {
                    LogTrace("No sheets to be exported...");
                    return(false);
                }

                using (var trans = new Transaction(doc, "Export DWG"))
                {
                    LogTrace("Starting the export task...");

                    try
                    {
                        if (trans.Start() == TransactionStatus.Started)
                        {
                            var dwgSettings = ExportDWGSettings.FindByName(doc, "Forge");
                            if (dwgSettings == null)
                            {
                                dwgSettings = ExportDWGSettings.Create(doc, "Forge");
                                trans.Commit();
                            }

                            var exportOpts = dwgSettings.GetDWGExportOptions();
                            exportOpts.MergedViews = true;

                            LogTrace("Exporting...");

                            doc.Export(exportPath, "DA4R", sheetIds, exportOpts);
                        }
                    }
                    catch (Autodesk.Revit.Exceptions.InvalidPathArgumentException ex)
                    {
                        this.PrintError(ex);
                        return(false);
                    }
                    catch (Autodesk.Revit.Exceptions.ArgumentException ex)
                    {
                        this.PrintError(ex);
                        return(false);
                    }
                    catch (Autodesk.Revit.Exceptions.InvalidOperationException ex)
                    {
                        this.PrintError(ex);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        this.PrintError(ex);
                        return(false);
                    }
                    finally
                    {
                        if (trans.HasStarted() == true)
                        {
                            trans.RollBack();
                        }
                    }
                }
            }

            return(true);
        }