Ejemplo n.º 1
0
 private static bool IsScheduleEmpty(Autodesk.Revit.DB.ViewSchedule schedule)
 {
     using (FilteredElementCollector collector = new FilteredElementCollector(Document, schedule.Id))
     {
         return(!collector.Any());
     }
 }
Ejemplo n.º 2
0
 public static ScheduleView Wrap(Autodesk.Revit.DB.ViewSchedule view, bool isRevitOwned)
 {
     return(ScheduleView.FromExisting(view, isRevitOwned));
 }
Ejemplo n.º 3
0
        public RevitUI.Result Execute(RevitUI.ExternalCommandData commandData, ref string message, RevitDB.ElementSet elements)
        {
            RevitUI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            RevitDB.Document   doc   = uidoc.Document;
            if (doc.IsFamilyDocument)//感觉族文档没必要
            {
                RevitUI.TaskDialog.Show("Revit", "该操作仅适用项目文档,不适用族文档!");
                return(RevitUI.Result.Succeeded);
            }
            try
            {
                RevitDB.ViewSchedule     vs   = doc.ActiveView as RevitDB.ViewSchedule;
                RevitDB.TableData        td   = vs.GetTableData();
                RevitDB.TableSectionData tsdh = td.GetSectionData(RevitDB.SectionType.Header);
                RevitDB.TableSectionData tsdb = td.GetSectionData(RevitDB.SectionType.Body);

                Excel.Application app = new Excel.Application();
                Excel.Workbooks   wbs = app.Workbooks;
                Excel.Workbook    wb  = wbs.Add(Type.Missing);
                Excel.Worksheet   ws  = wb.Worksheets["Sheet1"];

                int cs = tsdb.NumberOfColumns;
                int rs = tsdb.NumberOfRows;

                Excel.Range rg1 = ws.Cells[1, 1];
                Excel.Range rg2 = ws.Cells[1, cs];
                rg1.Value = vs.GetCellText(RevitDB.SectionType.Header, 0, 0);
                rg2.Value = "";
                Excel.Range rg = ws.get_Range(rg1, rg2);
                rg.Merge();
                rg.Font.Name           = "黑体";
                rg.Font.Bold           = 400;
                rg.Font.Size           = 14;
                rg.Font.ColorIndex     = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.HorizontalAlignment = Excel.Constants.xlCenter;
                rg.RowHeight           = 25;

                for (int i = 0; i < rs; i++)
                {
                    for (int j = 0; j < cs; j++)
                    {
                        RevitDB.CellType ct = tsdb.GetCellType(i, j);
                        ws.Cells[i + 2, j + 1] = vs.GetCellText(RevitDB.SectionType.Body, i, j);
                    }
                }

                rg1                    = ws.Cells[2, 1];
                rg2                    = ws.Cells[rs + 1, cs];
                rg                     = ws.get_Range(rg1, rg2);
                rg.Font.Name           = "仿宋";
                rg.Font.Size           = 11;
                rg.Font.ColorIndex     = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.HorizontalAlignment = Excel.Constants.xlCenter;
                rg.Borders.ColorIndex  = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.Borders.LineStyle   = Excel.XlLineStyle.xlContinuous;
                rg.EntireColumn.AutoFit();
                rg.RowHeight = 20;

                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).Weight        = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).ColorIndex    = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).Weight     = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).ColorIndex = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).Weight       = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).ColorIndex   = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).Weight      = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).ColorIndex  = 3;

                SaveFileDialog sf = new SaveFileDialog();
                sf.Title        = "Revit";
                sf.AddExtension = true;
                sf.Filter       = "Excel2007文件|*.xlsx|Excel2003文件|*.xls|文本文件|*.txt|所有文件|*.*";
                sf.FileName     = vs.ViewName;
                if (DialogResult.OK == sf.ShowDialog())
                {
                    wb.SaveAs(sf.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                }

                app.AlertBeforeOverwriting = false;
                wb.Close(true, Type.Missing, Type.Missing);
                wbs.Close();
                app.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                wb  = null;
                wbs = null;
                app = null;
                GC.Collect();
            }
            catch (Exception)
            {
                return(RevitUI.Result.Cancelled);
            }

            RevitUI.TaskDialog.Show("Revit", "Revit Export Excel Successful!");
            return(RevitUI.Result.Succeeded);
        }
Ejemplo n.º 4
0
 public Schedule(Autodesk.Revit.DB.ViewSchedule viewSchedule)
 {
     RevitViewSchedule = viewSchedule;
     RevitName         = RevitViewSchedule.Name;
     ExportName        = RevitName + ".txt";
 }