Beispiel #1
0
        private bool ExportDWG(Document doc, string folder, string name, ElementId viewid, string optionname)
        {
            DWGExportOptions dwgOptions = null;
            IList <string>   setupNames = BaseExportOptions.GetPredefinedSetupNames(doc);
            List <ElementId> ids        = new List <ElementId>();

            foreach (string n in setupNames)
            {
                if (n == optionname)
                {
                    dwgOptions = DWGExportOptions.GetPredefinedOptions(doc, name);
                }
            }

            ids.Add(viewid);

            try
            {
                doc.Export(folder, name, ids, dwgOptions);
                return(true);
            }
            catch (Exception e)
            {
                string message = e.Message;

                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Exports the view to DWG with the view name as the output file name.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="destination"></param>
        /// <param name="exportOptionsName"></param>
        /// <returns></returns>
        public static bool ExportDWG(Revit.Elements.Views.View view, string destination, string exportOptionsName)
        {
            var doc   = DocumentManager.Instance.CurrentDBDocument;
            var iView = view.InternalElement as Autodesk.Revit.DB.View;

            doc.Export(destination, iView.ViewName, new[] { iView.Id }, DWGExportOptions.GetPredefinedOptions(doc, exportOptionsName));
            return(true);
        }
Beispiel #3
0
        public static bool ExportDWG(Document document, Autodesk.Revit.DB.View view, string setupName, string fileName, string folder)
        {
            bool exported = false;
            // Get the predefined setups and use the one with the given name.
            IList <string> setupNames = BaseExportOptions.GetPredefinedSetupNames(document);

            foreach (string name in setupNames)
            {
                if (name.CompareTo(setupName) == 0)
                {
                    // Export using the predefined options
                    DWGExportOptions dwgOptions = DWGExportOptions.GetPredefinedOptions(document, name);
                    // Export the active view
                    ICollection <ElementId> views = new List <ElementId>();
                    views.Add(view.Id);
                    // The document has to be saved already, therefore it has a valid PathName.
                    exported = document.Export(folder, fileName, views, dwgOptions);
                    break;
                }
            }

            return(exported);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            //Handling and Dismissing a Warning Message
            //https://thebuildingcoder.typepad.com/blog/2013/03/export-wall-parts-individually-to-dxf.html
            uiapp.DialogBoxShowing += new EventHandler <DialogBoxShowingEventArgs>(OnDialogBoxShowing);

            IList <string> dWGExportOptions = DWGExportOptions.GetPredefinedSetupNames(doc);

            //            List<ViewScheduleOption> viewScheduleOptions = Helpers.GetViewScheduleOptions(doc);

            //find all the sheet list
            List <ViewSchedule> viewSchedule = Helpers.SheetList(doc);

            int counter = 0;

            try
            {
                using (var form = new Form1())
                {
                    //set the form export settings
                    form.CboxExportSettingsDataSource = dWGExportOptions;
                    //set the form sheets
                    form.CboxSheetDataSource = viewSchedule;
                    //set the form title
                    form.Text = "Mx CADD Export Sheets";
                    //use ShowDialog to show the form as a modal dialog box.
                    form.ShowDialog();

                    //if the user hits cancel just drop out of macro
                    if (form.DialogResult == winForm.DialogResult.Cancel)
                    {
                        return(Result.Cancelled);
                    }

                    string destinationFolder = form.TBoxDestinationFolder;

                    //string[] sheetNumbers = form.tboxSelectedSheets.Split(' ');

                    string exportSettings = form.TBoxExportSettings;

                    DWGExportOptions dwgOptions = DWGExportOptions.GetPredefinedOptions(doc, form.TBoxExportSettings);

                    if (dwgOptions == null)
                    {
                        TaskDialog.Show("Error", "Export setting not found");
                        return(Result.Failed);
                    }

                    if (dwgOptions.MergedViews == false)
                    {
                        TaskDialog.Show("Error", "Please unselect export view as external reference.");
                        return(Result.Failed);
                    }

                    if (dwgOptions.TargetUnit != ExportUnit.Millimeter)
                    {
                        TaskDialog.Show("Error", "Export units not set to Millimeter. Please fix this before exporting.");
                        return(Result.Failed);
                    }

                    ICollection <ElementId> categoryToIsolate = new List <ElementId>();

                    Categories groups = doc.Settings.Categories;

                    categoryToIsolate.Add(groups.get_Item(BuiltInCategory.OST_Loads).Id);


                    //selected Sheet List
                    ViewSchedule selectedSheetList = form.selectedViewSchedule;

                    //Sheets in selected sheet list
                    var selectedSheets = new FilteredElementCollector(doc, selectedSheetList.Id).OfClass(typeof(ViewSheet)).ToElements().Cast <ViewSheet>();

                    int    n       = selectedSheets.Count();
                    string s       = "{0} of " + n.ToString() + " sheets exported...";
                    string caption = "Export Sheets";

                    var watch = System.Diagnostics.Stopwatch.StartNew();

                    using (ProgressForm pf = new ProgressForm(caption, s, n))
                    {
                        using (Transaction t = new Transaction(doc, "Hide categories"))
                        {
                            t.Start();

                            foreach (ViewSheet vs in selectedSheets)
                            {
                                if (pf.abortFlag)
                                {
                                    break;
                                }

                                //ViewSheet vs = allSheets.Where(x => x.SheetNumber == sheetNumber).First();

                                //if the parameter does not exists use the SheetNumber
                                string CAADparameter = vs.LookupParameter("CADD File Name").AsString() ?? vs.SheetNumber;

                                //IList<Parameter> viewParams = vs.GetParameters("CADD File Name");
                                //string CAADparameter = viewParams.First().AsString();

                                //remove white spaces from the name
                                string fileName = Helpers.RemoveWhitespace(CAADparameter);

                                //select all the views placed on the sheet
                                ISet <ElementId> views = vs.GetAllPlacedViews();

                                //select planViewsOnly
                                List <View> planViewsOnly = Helpers.FilterPlanViewport(doc, views);

                                //select keynote and exports them before isolating categories

                                //count the sheets with Floor,Ceiling,Engineering and Area plans
                                int hasArchOrStrViewports = 0;

                                foreach (View planView in planViewsOnly)
                                {
                                    if (form.HideViewportContent)
                                    {
                                        planView.IsolateCategoriesTemporary(categoryToIsolate);
                                    }
                                    hasArchOrStrViewports += 1;
                                }

                                if (!Helpers.ExportDWG(doc, vs, exportSettings, fileName, destinationFolder))
                                {
                                    TaskDialog.Show("Error", "Check that the destination folder exists");
                                }
                                else
                                {
                                    counter += 1;
                                }

                                pf.Increment();
                            }

                            t.RollBack();
                            //t.Commit();
                        }//close using transaction
                    }

                    watch.Stop();
                    var elapsedMinutes = watch.ElapsedMilliseconds / 1000 / 60;

                    TaskDialog.Show("Done", $"{counter} sheets have been exported in {elapsedMinutes} min.");
                }//close using form
                return(Result.Succeeded);
            }
            catch (System.NullReferenceException)
            {
                TaskDialog.Show("Error", "Check parameter \"CADD File Name exists\" ");
                return(Result.Failed);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return(Result.Failed);
            }
            finally
            {
                uiapp.DialogBoxShowing -= new EventHandler <DialogBoxShowingEventArgs>(OnDialogBoxShowing);
            }
        }
Beispiel #5
0
        private void FreezeDrawing(Document doc, View view, OptionsForm optionsForm, String viewName)
        {
            // Create the ViewSheetToExport
            ViewSheet tempViewSheet = CreateViewSheetToExport(doc);

            // Create the viewport with the view on tempViewSheet
            _ = Viewport.Create(doc, tempViewSheet.Id, view.Id, new XYZ());


            // Create a list, because the method export needs it
            List <ElementId> viewSheets = new List <ElementId> {
                tempViewSheet.Id
            };

            // Export
            doc.Export(this.Directory, this._dwgName, viewSheets,
                       DWGExportOptions.GetPredefinedOptions(doc, optionsForm.DWGExportOptionsName));

            // Copying file according to optionsForm
            if (optionsForm.CopyDWGToFolder)
            {
                // try to copy
                try
                {
                    File.Copy(this.Directory + "\\" + this._dwgName + ".dwg",
                              String.Join("\\", optionsForm.FolderToSave, viewName + ".dwg"));
                }

                catch (IOException ex)
                {
                    if (MessageBox.Show(ex.Message + " Deseja substituir arquivo?",
                                        "Substituir arquivo",
                                        MessageBoxButtons.YesNo)
                        == DialogResult.Yes)
                    {
                        File.Copy(this.Directory + "\\" + this._dwgName + ".dwg",
                                  String.Join("\\", optionsForm.FolderToSave, viewName + ".dwg"), true);
                    }
                }
            }


            // Creating view
            ViewFamilyType viewFamilyType = (from element in (new List <Element>
                                                                  (new FilteredElementCollector(doc)
                                                                  .OfClass(typeof(ViewFamilyType))
                                                                  .ToElements()).ToList())
                                             where (element as ViewFamilyType).ViewFamily.Equals(ViewFamily.Drafting)
                                             select(element as ViewFamilyType))
                                            .First();
            View draftingView = ViewDrafting.Create(doc, viewFamilyType.Id);

            // Import
            ElementId elementId;

            doc.Import(this.Directory + "\\" + this._dwgName + ".dwg",
                       optionsForm.DWGImportOptions, draftingView, out elementId);

            // Deleting aux ViewSheet (according to optionsForm and DWG
            doc.Delete(tempViewSheet.Id);
            File.Delete(this.Directory + "\\" + this._dwgName + ".dwg");
        }