Esempio n. 1
0
        private static void CopyMassValues(CopyMassOperation operation, TableSectionData tsDada, int row, IEnumerable <Element> elements)
        {
            var reserve = 1d;

            if (!string.IsNullOrEmpty(operation.ReserveParameter))
            {
                if (RevitFunctions.TryGetGlobalReserveValue(_doc, operation.ReserveParameter, out double outValue))
                {
                    reserve = outValue;
                }
            }
            else
            {
                reserve = operation.Reserve;
            }

            var value  = 0d;
            var column = operation.SourceColumn - 1;

            if (column >= 0)
            {
                if (column < tsDada.NumberOfColumns)
                {
                    var data = tsDada.GetCellText(row, column);
                    if (double.TryParse(data.Replace(',', '.'), out var outValue))
                    {
                        value = outValue;
                    }
                }
            }

            RevitFunctions.CopyMassValue(_doc, operation.Parameter, value * reserve, elements);
        }
Esempio n. 2
0
        /// <summary>
        /// Заполнение листа моделей значением параметров
        /// </summary>
        /// <param name="rowModelList"></param>
        private void FillListModelParameters(List <RowModel> rowModelList)
        {
            foreach (var parameter in _parametersList)
            {
                OpenColumnByName(parameter);
                for (int j = 4; j < _tsd.NumberOfRows; j++)
                {
                    if (parameter == "КМ.ГруппаКонструкций" || parameter == "Арм.НомерПодтипаФормы")
                    {
                        var el = rowModelList.Where(i => i.NumberOfRow == j).ToList().First();
                        if (parameter == "КМ.ГруппаКонструкций")
                        {
                            el.ArmNumberOfForm = _tsd.GetCellText(j, _tsd.LastColumnNumber);
                        }
                        else if (parameter == "Арм.НомерПодтипаФормы")
                        {
                            if (_tsd.GetCellText(j, _tsd.LastColumnNumber) == string.Empty)
                            {
                                el.ArmNumberOfUnderForm = "0";
                            }
                            else
                            {
                                el.ArmNumberOfUnderForm = _tsd.GetCellText(j, _tsd.LastColumnNumber);
                            }
                        }
                    }
                    else
                    {
                        var el = rowModelList.Where(i => i.NumberOfRow == j).ToList().First();

                        var test = _viewSchedule.GetCellText(SectionType.Body, j, _tsd.LastColumnNumber);
                        if (_viewSchedule.GetCellText(SectionType.Body, j, _tsd.LastColumnNumber) != string.Empty)
                        {
                            var newCell = new ScheduleFieldModel()
                            {
                                FieldName     = parameter,
                                ValueAsString = _viewSchedule.GetCellText(SectionType.Body, j, _tsd.LastColumnNumber)
                            };
                            el.SheduleFieldList.Add(newCell);
                        }
                    }
                }
                CloseColumnByName(parameter);
            }
        }
Esempio n. 3
0
        private void HideEmptyColumns(ElementId id)
        {
            if (id == ElementId.InvalidElementId)
            {
                return;
            }

            ViewSchedule viewSchd = m_doc.GetElement(id)
                                    as ViewSchedule;
            ScheduleDefinition schdDef   = viewSchd.Definition;
            TableSectionData   tableData =
                viewSchd.GetTableData().GetSectionData(SectionType.Body);

            Func <ScheduleFieldId, bool> filterHiddenFields = delegate(ScheduleFieldId fId)
            {
                if (schdDef.GetField(fId).IsHidden)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            IList <ScheduleFieldId> visibleFields = schdDef
                                                    .GetFieldOrder()
                                                    .Where(filterHiddenFields)
                                                    .ToList();

            StringBuilder strBld = new StringBuilder();

            for (int i = tableData.FirstColumnNumber + 2; i <= tableData.LastColumnNumber; ++i)
            {
                double sum = 0;

                for (int j = tableData.FirstRowNumber + 1; j <= tableData.LastRowNumber; ++j)
                {
                    string cellContent = tableData.GetCellText(j, i);
                    strBld.AppendFormat("({0}, {1}) = {2}\n", i, j, cellContent);
                    double cellValue;
                    if (Double.TryParse(cellContent, out cellValue))
                    {
                        sum += cellValue;
                    }
                }

                // if the current column holds no value, then have it hidden
                if (sum == 0)
                {
                    ScheduleField field = schdDef.GetField(visibleFields[i]);
                    field.IsHidden = true;
                }
            }
            System.Diagnostics.Trace.Write(strBld.ToString());
        }
Esempio n. 4
0
        internal void HideZeroFieldsMaterialTakeOff()
        {
            ViewSchedule         viewSchedule  = m_doc.GetElement(m_createdScheduleId) as ViewSchedule;
            ScheduleDefinition   scheduleDef   = viewSchedule.Definition;
            TableData            tableData     = viewSchedule.GetTableData();
            TableSectionData     tableSecData  = tableData.GetSectionData(SectionType.Body);
            List <ScheduleField> visibleFields = scheduleDef.GetFieldOrder().Select(id => scheduleDef.GetField(id)).Where(f => !f.IsHidden).ToList();

            System.Text.StringBuilder strBld = new System.Text.StringBuilder();

            using (Transaction t = new Transaction(viewSchedule.Document))
            {
                t.Start("Hide Zeroed Fields");
                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)
                        {
                            strBld.AppendFormat("{0} = {1}; column = {2}\n",
                                                tableSecData.GetCellText(tableSecData.FirstRowNumber + 4, i), tableSecData.GetCellText(j, i), i);
                            double tmp;
                            if (Double.TryParse(tableSecData.GetCellText(j, i), out tmp))
                            {
                                total += tmp;
                            }
                        }

                        if (total == 0)
                        {
                            visibleFields[i].IsHidden = true;
                        }
                    }
                }
                t.Commit();
            }
            Tracer.Write(strBld.ToString());
        }
Esempio n. 5
0
        void ChangeTitle(ViewSchedule vs, string assemblyName)
        {
            ScheduleDefinition sd       = vs.Definition;
            TableData          td       = vs.GetTableData();
            TableSectionData   tsd      = td.GetSectionData(SectionType.Header);
            string             oldValue = tsd.GetCellText(tsd.FirstRowNumber, tsd.FirstColumnNumber);

            Tracer.Write($"oldValue={oldValue}");
            string newValue = string.Empty;

            for (int i = 0; i < oldValue.Split(' ').Length - 1; i++)
            {
                newValue += oldValue.Split(' ')[i] + " ";
            }
            newValue += assemblyName;
            Tracer.Write($"newValue={newValue}");
            tsd.SetCellText(tsd.FirstRowNumber, tsd.FirstColumnNumber, newValue);
        }
Esempio n. 6
0
        private static void CopyStringValues(CopyStringOperation operation, TableSectionData tsDada, int row, List <Element> elements)
        {
            var value  = string.Empty;
            var column = operation.SourceColumn - 1;

            if (column >= 0)
            {
                if (column < tsDada.NumberOfColumns)
                {
                    value = tsDada.GetCellText(row, column);
                }
            }
            else
            {
                value = operation.Value;
            }

            RevitFunctions.CopyStringValue(_doc, operation.Parameter, value, elements);
        }
Esempio n. 7
0
 private static void Check(TableSectionData section)
 {
     using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
     {
         for (int i = 0; i < section.NumberOfRows; i++)
         {
             for (int j = 0; j < section.NumberOfColumns; j++)
             {
                 string text = section.GetCellText(i, j);
                 foreach (string word in text.Split(' '))
                 {
                     if (!hunspell.Spell(word))
                     {
                         TableCellStyle style = section.GetTableCellStyle(i, j);
                         style.BackgroundColor = INCORRECT_SPELLING_BACKGROUND_COLOR;
                         section.SetCellStyle(i, j, style);
                     }
                 }
             }
         }
     }
 }
Esempio n. 8
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document           doc  = commandData.Application.ActiveUIDocument.Document;
            ViewSchedule       vs   = commandData.Application.ActiveUIDocument.ActiveView as ViewSchedule;
            ScheduleDefinition sdef = null;

            if (vs == null)
            {
                Selection sel = commandData.Application.ActiveUIDocument.Selection;
                if (sel.GetElementIds().Count == 0)
                {
                    return(Result.Failed);
                }
                ScheduleSheetInstance ssi = doc.GetElement(sel.GetElementIds().First()) as ScheduleSheetInstance;
                if (ssi == null)
                {
                    return(Result.Failed);
                }
                if (!ssi.Name.Contains("ВРС"))
                {
                    return(Result.Failed);
                }
                vs = doc.GetElement(ssi.ScheduleId) as ViewSchedule;
            }
            sdef = vs.Definition;


            int firstWeightCell   = 0;
            int startHiddenFields = 0;
            int borderCell        = 9999;

            //определяю первую и последнюю ячейку с массой
            for (int i = 0; i < sdef.GetFieldCount(); i++)
            {
                ScheduleField sfield   = sdef.GetField(i);
                string        cellName = sfield.GetName();
                if (firstWeightCell == 0)
                {
                    if (char.IsNumber(cellName[0]))
                    {
                        firstWeightCell = i;
                    }
                    else
                    {
                        if (sfield.IsHidden)
                        {
                            startHiddenFields++;
                        }
                    }
                }
                if (cellName.StartsWith("="))
                {
                    borderCell = i;
                    break;
                }
            }

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Отобразить все ячейки");
                for (int i = firstWeightCell; i < borderCell; i++)
                {
                    ScheduleField sfield   = sdef.GetField(i);
                    string        cellName = sfield.GetName();
                    sfield.IsHidden = false;
                }


                doc.Regenerate();

                TableData        tdata = vs.GetTableData();
                TableSectionData tsd   = tdata.GetSectionData(SectionType.Body);
                int firstRownumber     = tsd.FirstRowNumber;
                int lastRowNumber      = tsd.LastRowNumber;
                int rowsCount          = lastRowNumber - firstRownumber;

                for (int i = firstWeightCell; i < borderCell; i++)
                {
                    ScheduleField sfield   = sdef.GetField(i);
                    string        cellName = sfield.GetName();

                    List <string> values = new List <string>();
                    for (int j = firstRownumber; j <= lastRowNumber; j++)
                    {
                        string cellText = tsd.GetCellText(j, i - startHiddenFields);
                        values.Add(cellText);
                    }

                    bool checkOnlyTextAndZeros = OnlyTextAndZeros(values);
                    if (checkOnlyTextAndZeros)
                    {
                        sfield.IsHidden = true;
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
Esempio n. 9
0
        private RevitDataTable GetRevitDataTable(ViewSchedule schedule)
        {
            ScheduleDefinition scheduleDefinition = schedule.Definition;
            TableSectionData   bodyData           = schedule.GetTableData().GetSectionData(SectionType.Body);
            TableSectionData   headerData         = schedule.GetTableData().GetSectionData(SectionType.Header);

            RevitDataTable   dataTable   = new RevitDataTable(schedule.Name);
            RevitDataSection dataSection = new RevitDataSection("Без названия");

            dataTable.Sections.Add(dataSection);
            // заголовки
            int start_i;

            if (scheduleDefinition.ShowHeaders)
            {
                RevitDataRow header = new RevitDataRow(0);
                for (int col = 0; col < bodyData.NumberOfColumns; col++)
                {
                    RevitDataCell dataCell = new RevitDataCell(
                        schedule.GetCellText(SectionType.Body, 0, col),
                        bodyData.GetCellType(0, col),
                        bodyData.GetCellParamId(col));
                    header.Cells.Add(dataCell);
                }
                start_i          = 1;
                dataTable.Header = header;
            }
            else
            {
                start_i = 0;
            }
            //ищем секции
            for (int row = start_i; row < bodyData.NumberOfRows; row++)
            {
                if (bodyData.GetCellType(row, 0) == CellType.Text &&
                    bodyData.GetMergedCell(row, 0).Right == bodyData.LastColumnNumber)
                {
                    string header = bodyData.GetCellText(row, 0);
                    header      = string.IsNullOrEmpty(header) ? "Без названия" : header;
                    dataSection = new RevitDataSection(header);
                    dataTable.Sections.Add(dataSection);
                    continue;
                }

                RevitDataRow dataRow = new RevitDataRow(row);
                for (int col = 0; col < bodyData.NumberOfColumns; col++)
                {
                    RevitDataCell dataCell = new RevitDataCell(
                        schedule.GetCellText(SectionType.Body, row, col),
                        bodyData.GetCellType(row, col),
                        bodyData.GetCellParamId(col));
                    dataRow.Cells.Add(dataCell);
                }
                dataSection.Rows.Add(dataRow);
            }
            if (dataTable["Без названия"].Rows.Count == 0)
            {
                dataTable.Sections.Remove(dataTable["Без названия"]);
            }
            return(dataTable);
        }