Exemplo n.º 1
0
 /// <summary>
 /// Create a View from a user selected Element.
 /// </summary>
 /// <param name="view"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static ScheduleView FromExisting(Autodesk.Revit.DB.ViewSchedule view, bool isRevitOwned)
 {
     return(new ScheduleView(view)
     {
         IsRevitOwned = isRevitOwned
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Set the InternalViewSchedule property and the associated element id and unique id
 /// </summary>
 /// <param name="view"></param>
 private void InternalSetScheduleView(Autodesk.Revit.DB.ViewSchedule view)
 {
     this.InternalViewSchedule    = view;
     this.InternalElementId       = view.Id;
     this.InternalUniqueId        = view.UniqueId;
     this.InternalScheduleFilters = view.Definition.GetFilters();
 }
Exemplo n.º 3
0
        private static Autodesk.Revit.DB.ViewSchedule CreateViewSchedule(Category category, string name, ScheduleType type)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            Autodesk.Revit.DB.ViewSchedule viewSchedule = null;
            switch (type)
            {
            case ScheduleType.KeySchedule:
                viewSchedule      = Autodesk.Revit.DB.ViewSchedule.CreateKeySchedule(doc, new Autodesk.Revit.DB.ElementId(category.Id));
                viewSchedule.Name = name;
                break;

            case ScheduleType.RegularSchedule:
                viewSchedule      = Autodesk.Revit.DB.ViewSchedule.CreateSchedule(doc, new Autodesk.Revit.DB.ElementId(category.Id));
                viewSchedule.Name = name;
                break;

            case ScheduleType.MaterialTakeoff:
                viewSchedule      = Autodesk.Revit.DB.ViewSchedule.CreateMaterialTakeoff(doc, new Autodesk.Revit.DB.ElementId(category.Id));
                viewSchedule.Name = name;
                break;
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(viewSchedule);
        }
Exemplo n.º 4
0
 private void ButtonOk_Click(object sender, EventArgs e)
 {
     selectedViewSchedule  = comboBoxSheetsSchedules.SelectedItem as Autodesk.Revit.DB.ViewSchedule;
     TBoxExportSettings    = cboxExportSettings.SelectedValue.ToString();
     TBoxDestinationFolder = textBoxFolder.Text;
     HideViewportContent   = cBoxHideViewportContent.Checked;
 }
 private void buttonOk_Click(object sender, EventArgs e)
 {
     maxWidth             = Convert.ToInt16(textBoxWidth.Text);
     maxHeight            = Convert.ToInt16(textBoxHeight.Text);
     centerX              = Convert.ToInt16(textBoxCenterX.Text);
     centerY              = Convert.ToInt16(textBoxCenterY.Text);
     selectedViewSchedule = comboBoxSheetsSchedules.SelectedItem as Autodesk.Revit.DB.ViewSchedule;
 }
Exemplo n.º 6
0
        public static void ExportToExcel(RvtSchedule schedule, string outputDirectory)
        {
            // Obtain and prepare data for export to excel
            object[,] data;
            int    row;
            int    column;
            string csvpath = GetCSVFilePath(schedule);

            FormatDataAsArray(csvpath, schedule, out data, out row, out column);

            try {
                // Open Excel
                m_excelApp = new Excel.Application();
                m_excelApp.EnableEvents   = false;
                m_excelApp.Visible        = false;
                m_excelApp.Interactive    = false;
                m_excelApp.ScreenUpdating = false;

                m_workbook  = m_excelApp.Workbooks.Add();
                m_worksheet = m_excelApp.ActiveSheet;

                // Write the data to the file
                var startCell  = (Excel.Range)m_worksheet.Cells[1, 1];
                var endCell    = (Excel.Range)m_worksheet.Cells[row, column];
                var writeRange = m_worksheet.Range[startCell, endCell];
                writeRange.Value = data;

                // Format a worksheet
                m_worksheet.Columns.AutoFit();

                // Restore interactivity, GUI updates and calculation
                m_excelApp.Interactive    = true;
                m_excelApp.ScreenUpdating = true;

                // save the workbook and exit
                m_workbook.SaveAs(outputDirectory + "\\" + RemoveIllegalCharacters(schedule.Name),
                                  Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue,
                                  Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlUserResolution,
                                  misValue, misValue, misValue, misValue);
            }
            catch (Exception ex) {
                Trace.Write("Exception while working with excel" +
                            ex.Message);
            }
            finally {
                // Close the workbook and app
                m_workbook.Close(false, misValue, misValue);
                m_excelApp.Quit();

                // Release COM objects
                ReleaseObject(m_excelApp);
                ReleaseObject(m_workbook);
                ReleaseObject(m_worksheet);
            }
        }
Exemplo n.º 7
0
        private static void FormatDataAsArray(string csvfilename, RvtSchedule schedule,
                                              out object[,] data, out int row, out int column)
        {
            row    = 0;
            column = 0;
            data   = new object[1000, 500];

            using (StreamReader stream = File.OpenText(csvfilename)) {
                string   line;
                string[] a;

                while ((line = stream.ReadLine()) != null)
                {
                    a = line
                        .Split(m_tabs)
                        .Select <string, string>(s => s.Trim(m_quotes))
                        .ToArray();

                    // First line of text file contains
                    // schedule name
                    if (schedule.Definition.ShowTitle && row == 0)
                    {
                        data[row, column] = a[0];
                        ++row;
                        continue;
                    }

                    // Second line of text file contains
                    // schedule column names
                    if (schedule.Definition.ShowHeaders && (row == 0 || row == 1))
                    {
                        for (int i = 0; i < a.Count(); i++)
                        {
                            data[row, column] = a[i];
                            ++column;
                        }
                        ++row;
                        continue;
                    }

                    // Remaining lines define schedule data
                    for (int i = 0; i < a.Count(); i++)
                    {
                        data[row, i] = a[i];
                        if (column == 0)
                        {
                            column = a.Count();
                        }
                    }
                    ++row;
                }
                stream.Close();
            }
        }
Exemplo n.º 8
0
        private static string GetCSVFilePath(RvtSchedule vs)
        {
            // Create a temp file for exporting a .csv file
            string tempPath     = System.IO.Path.GetTempPath();
            string scheduleName = RemoveIllegalCharacters(vs.Name);

            Trace.Write("After: " + scheduleName);

            vs.Export(tempPath, counter + ".txt",
                      new Autodesk.Revit.DB.ViewScheduleExportOptions());

            string filepath = tempPath + counter + ".txt";

            ++counter;

            return(filepath);
        }
Exemplo n.º 9
0
        internal void HideZeroFieldsMaterialTakeOff(Document doc)
        {
            if (Subschedules.Count == 0 ||
                Subschedules[0].Id == ElementId.InvalidElementId)
            {
                return;
            }

            ViewSchedule       viewSchedule = doc.GetElement(Subschedules[0].Id) as ViewSchedule;
            ScheduleDefinition scheduleDef  = viewSchedule.Definition;
            TableData          tableData    = viewSchedule.GetTableData();
            TableSectionData   tableSecData = tableData
                                              .GetSectionData(Autodesk.Revit.DB.SectionType.Body);
            List <ScheduleField> visibleFields = scheduleDef
                                                 .GetFieldOrder()
                                                 .Select(id => scheduleDef.GetField(id))
                                                 .Where(f => !f.IsHidden)
                                                 .ToList();

            for (int i = tableSecData.FirstColumnNumber; i <= tableSecData.LastColumnNumber; ++i)
            {
                if (tableSecData.GetCellText(tableSecData.FirstRowNumber + 5, i) == "0")
                {
                    double total = 0;

                    for (int j = tableSecData.FirstRowNumber + 5; j <= tableSecData.LastRowNumber; ++j)
                    {
                        double tmp;
                        if (Double.TryParse(tableSecData.GetCellText(j, i), out tmp))
                        {
                            total += tmp;
                        }
                    }

                    if (total == 0)
                    {
                        visibleFields[i].IsHidden = true;
                    }
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initialize a ScheduleView element
 /// </summary>
 private void InitScheduleView(Autodesk.Revit.DB.ViewSchedule view)
 {
     InternalSetScheduleView(view);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Private constructor
 /// </summary>
 private ScheduleView(Autodesk.Revit.DB.ViewSchedule view)
 {
     SafeInit(() => InitScheduleView(view));
 }
Exemplo n.º 12
0
        public static void ExportToNewSheet(Excel.Workbook workbook, string filename, RvtSchedule schedule)
        {
            Excel.Worksheet worksheet = null;
            int             row;
            int             column;

            object[,] data;
            FormatDataAsArray(filename, schedule,
                              out data, out row, out column);

            try {
                // add a new worksheet and begin to perform operations
                worksheet = workbook.Sheets.Add();

                /*string scheduleName = schedule.Name;
                 * string currWorksheetName = workSheet.Name;
                 * try {
                 *  workSheet.Name = RemoveIllegalCharacters(scheduleName);
                 * }
                 * catch(Exception ex) {
                 *  workSheet.Name = currWorksheetName;
                 * }*/

                worksheet.Activate();

                // select a range and assign the data to it
                var startCell  = (Excel.Range)worksheet.Cells[1, 1];
                var endCell    = (Excel.Range)worksheet.Cells[row, column];
                var writeRange = worksheet.Range[startCell, endCell];
                writeRange.Value = data;

                // Format a worksheet
                worksheet.Columns.AutoFit();
            }
            catch (Exception ex) {
                Trace.Write(string.Format
                                ("Exception while working with a worksheet!\n{0},{1}",
                                ex.Message, ex.StackTrace));
            }
            finally {
                // Release a COM object
                ReleaseObject(worksheet);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 ///     Set the InternalViewSchedule property and the associated element id and unique id
 /// </summary>
 /// <param name="view"></param>
 private void InternalSetScheduleView(Autodesk.Revit.DB.ViewSchedule view)
 {
     this.InternalViewSchedule = view;
     this.InternalElementId    = view.Id;
     this.InternalUniqueId     = view.UniqueId;
 }
Exemplo n.º 14
0
 private void buttonOk_Click(object sender, EventArgs e)
 {
     selectedViewSchedule = comboBoxSheetsSchedules.SelectedItem as Autodesk.Revit.DB.ViewSchedule;
 }