Ejemplo n.º 1
0
        private void FindOrCreateDynamoErrorMaterial()
        {
            Dictionary <string, Material> materials
                = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument)
                  .OfClass(typeof(Material))
                  .Cast <Material>()
                  .ToDictionary <Material, string>(
                      e => e.Name);

            // First try to get or create the DynamoError material
            if (materials.ContainsKey("DynamoError"))
            {
                DynamoMaterialId = materials["DynamoError"].Id;
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(
                DocumentManager.Instance.CurrentDBDocument);

            var dynamoErrorMaterialId = Material.Create(DocumentManager.Instance.CurrentDBDocument, "DynamoError");
            var dynamoErrorMaterial   = DocumentManager.Instance.CurrentDBDocument.GetElement(dynamoErrorMaterialId) as Material;

            dynamoErrorMaterial.Transparency = 95;
            dynamoErrorMaterial.UseRenderAppearanceForShading = true;
            dynamoErrorMaterial.Color = new Color(255, 0, 0);
            DynamoErrorMaterialId     = dynamoErrorMaterial.Id;

            TransactionManager.Instance.ForceCloseTransaction();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Collects all of the imported DWGs.
        /// </summary>
        private void CollectImports()
        {
            var cadLinksDic = new FilteredElementCollector(_doc)
                              .OfClass(typeof(CADLinkType))
                              .Cast <CADLinkType>()
                              .Select(x => new CadLinkTypeWrapper(x))
                              .ToDictionary(key => key.Id, value => value);

            var imports = new FilteredElementCollector(_doc)
                          .OfClass(typeof(ImportInstance))
                          .Cast <ImportInstance>()
                          .ToList();

            foreach (var ii in imports)
            {
                var id = ii.GetTypeId();
                if (!cadLinksDic.ContainsKey(id))
                {
                    continue;
                }

                if (cadLinksDic[id].Instances == 0)
                {
                    cadLinksDic[id].IsViewSpecific = ii.ViewSpecific;
                    cadLinksDic[id].IsLinked       = ii.IsLinked;
                }
                cadLinksDic[id].Instances = cadLinksDic[id].Instances + 1;
            }

            Imports = new ObservableCollection <CadLinkTypeWrapper>(cadLinksDic.Values.OrderBy(x => x.Name));
        }
Ejemplo n.º 3
0
        private void FindOrCreateDynamoMaterial()
        {
            Dictionary <string, Material> materials
                = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument)
                  .OfClass(typeof(Material))
                  .Cast <Material>()
                  .ToDictionary <Material, string>(
                      e => e.Name);

            // First try to get or create the Dynamo material
            if (materials.ContainsKey("Dynamo"))
            {
                DynamoMaterialId = materials["Dynamo"].Id;
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(
                DocumentManager.Instance.CurrentDBDocument);

            var glass          = materials["Glass"];
            var dynamoMaterial = glass.Duplicate("Dynamo");

            dynamoMaterial.Color = new Color(255, 128, 0);
            DynamoMaterialId     = dynamoMaterial.Id;

            TransactionManager.Instance.ForceCloseTransaction();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Publishes information about groups in the model.
        /// </summary>
        /// <param name="doc">Revit Document.</param>
        /// <param name="groupsId">Id of the Groups Document in MongoDB.</param>
        public void PublishData(Document doc, string groupsId)
        {
            try
            {
                var gTypes = new FilteredElementCollector(doc)
                             .OfClass(typeof(GroupType))
                             .Cast <GroupType>()
                             .ToDictionary(x => x.Id, x => new GroupItem
                {
                    Name = x.Name,

                    // (Konrad) If there is a Detail Group attached to Model Group
                    // it will have the same name as Model Group but different Category.
                    Type = x.Category.Name == "Attached Detail Groups"
                            ? "Attached Detail Group"
                            : x.FamilyName
                });

                foreach (var gi in new FilteredElementCollector(doc).OfClass(typeof(Group)).Cast <Group>())
                {
                    var gTypeId = gi.GroupType.Id;
                    if (!gTypes.ContainsKey(gTypeId))
                    {
                        continue;
                    }

                    var gType = gTypes[gTypeId];
                    gType.Instances.Add(new GroupInstanceItem(gi));
                    gType.MemberCount = gi.GetMemberIds().Count;
                }

                var groupStats = new GroupDataItem
                {
                    Groups = gTypes.Values.ToList()
                };

                if (!ServerUtilities.Post(groupStats, "groups/" + groupsId + "/groupstats",
                                          out GroupsData unused))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to publish Groups Data.");
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieves all Group Types from the project.
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <GroupTypeWrapper> CollectGroups()
        {
            var gTypes = new FilteredElementCollector(Doc)
                         .OfClass(typeof(GroupType))
                         .Cast <GroupType>()
                         .ToDictionary(x => x.Id, x => new GroupTypeWrapper(x));

            foreach (var gi in new FilteredElementCollector(Doc).OfClass(typeof(Group)).Cast <Group>())
            {
                var gTypeId = gi.GroupType.Id;
                if (!gTypes.ContainsKey(gTypeId))
                {
                    continue;
                }

                var gType = gTypes[gTypeId];
                gType.MemberCount = gi.GetMemberIds().Count;
                gType.Instances.Add(gi.Id);
            }

            return(new ObservableCollection <GroupTypeWrapper>(gTypes.Values.ToList().OrderBy(x => x.Name)));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <TextStyleWrapper> CollectTextStyles()
        {
            var textTypes = new FilteredElementCollector(_doc)
                            .OfClass(typeof(TextNoteType))
                            .ToDictionary(x => x.Id, x => new TextStyleWrapper(x));

            var textInstances = new FilteredElementCollector(_doc)
                                .OfClass(typeof(TextNote))
                                .WhereElementIsNotElementType();

            foreach (var t in textInstances)
            {
                var key = t.GetTypeId();
                if (textTypes.ContainsKey(key))
                {
                    // increment instance count
                    textTypes[key].Count = textTypes[key].Count + 1;
                }
            }

            return(new ObservableCollection <TextStyleWrapper>(textTypes.Values));
        }
Ejemplo n.º 7
0
        public ObservableCollection <DimensionTypeWrapper> CollectDimensions()
        {
            var dTypes = new FilteredElementCollector(_doc)
                         .OfClass(typeof(DimensionType))
                         .Cast <DimensionType>()
                         .Where(x => !string.IsNullOrEmpty(x.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()))
                         .ToDictionary(x => x.Id, x => new DimensionTypeWrapper(x));

            var dInstances = new FilteredElementCollector(_doc)
                             .OfClass(typeof(Dimension))
                             .WhereElementIsNotElementType()
                             .Cast <Dimension>();

            foreach (var d in dInstances)
            {
                var key = d.GetTypeId();
                if (dTypes.ContainsKey(key))
                {
                    dTypes[key].Count = dTypes[key].Count + 1; // increment
                }
            }

            return(new ObservableCollection <DimensionTypeWrapper>(dTypes.Values.OrderBy(x => x.Name)));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Publishes information about linked models/images/object styles in the model.
        /// </summary>
        /// <param name="doc">Revit Document.</param>
        /// <param name="linksId">Id of the Links Document in MongoDB.</param>
        public void PublishData(Document doc, string linksId)
        {
            try
            {
                var dwgStyles = new FilteredElementCollector(doc)
                                .OfClass(typeof(GraphicsStyle))
                                .Cast <GraphicsStyle>()
                                .Where(x => x.GraphicsStyleCategory.Name.Contains(".dwg"))
                                .Select(x => x.GraphicsStyleCategory);

                var totalDwgStyles = dwgStyles.Sum(x => x.SubCategories.Size);

                var familyStyles = new FilteredElementCollector(doc)
                                   .OfClass(typeof(GraphicsStyle))
                                   .Cast <GraphicsStyle>()
                                   .Where(x => x.GraphicsStyleCategory.Name == "Imports in Families")
                                   .Select(x => x.GraphicsStyleCategory);
                var totalImportedStyles = familyStyles.Sum(x => x.SubCategories.Size);

                // (Konrad) Collect info about Images
                var allPlacedImageIds = new FilteredElementCollector(doc)
                                        .OfCategory(BuiltInCategory.OST_RasterImages)
                                        .Select(x => x.GetTypeId())
                                        .ToList();

                var totalUnusedImages = new FilteredElementCollector(doc)
                                        .OfClass(typeof(ImageType))
                                        .Excluding(allPlacedImageIds)
                                        .GetElementCount();

                // (Konrad) Collect all Linked Model info
                var totalLinkedCad = new FilteredElementCollector(doc)
                                     .OfClass(typeof(CADLinkType))
                                     .GetElementCount();

                var totalLinkedRvt = new FilteredElementCollector(doc)
                                     .OfClass(typeof(RevitLinkType))
                                     .GetElementCount();

                var cadLinksDic = new FilteredElementCollector(doc)
                                  .OfClass(typeof(CADLinkType))
                                  .Select(x => new DwgFileInfo {
                    Name = x.Name, ElementId = x.Id.IntegerValue
                })
                                  .ToDictionary(key => key.ElementId, value => value);

                var totalImportInstance = 0;
                foreach (var ii in new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)))
                {
                    totalImportInstance++;
                    var id = ii.GetTypeId().IntegerValue;
                    if (!cadLinksDic.ContainsKey(id))
                    {
                        continue;
                    }

                    if (cadLinksDic[id].Instances == 0)
                    {
                        cadLinksDic[id].IsViewSpecific = ii.ViewSpecific;
                        cadLinksDic[id].IsLinked       = ((ImportInstance)ii).IsLinked;
                    }
                    cadLinksDic[id].Instances = cadLinksDic[id].Instances + 1;
                }

                var linkStats = new LinkDataItem
                {
                    TotalImportedDwg    = totalImportInstance,
                    ImportedDwgFiles    = cadLinksDic.Values.ToList(),
                    UnusedLinkedImages  = totalUnusedImages,
                    TotalDwgStyles      = totalDwgStyles,
                    TotalImportedStyles = totalImportedStyles,
                    TotalLinkedModels   = totalLinkedCad + totalLinkedRvt,
                    TotalLinkedDwg      = totalLinkedCad
                };

                if (!ServerUtilities.Post(linkStats, "links/" + linksId + "/linkstats",
                                          out LinkDataItem unused))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to publish Links Data.");
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
        /// <summary>
        /// Получение сортированных элементов из спецификации с не установленной галочкой "Для каждого экземпляра"
        /// </summary>
        /// <remarks>Алгоритм с удалением строк</remarks>
        /// <param name="viewSchedule">Вид спецификации</param>
        private IEnumerable <RowData <int> > GetSortedElementsFromNotItemizedScheduleByDeleteRows(
            ViewSchedule viewSchedule)
        {
            var sortedElements = new List <RowData <int> >();

            var allElements = new FilteredElementCollector(viewSchedule.Document, viewSchedule.Id)
                              .Where(e => e.IsValidObject && e.Category != null && e.Category.CategoryType != CategoryType.AnalyticalModel)
                              .Select(e => e.Id.IntegerValue)
                              .ToList();

            var sectionData = viewSchedule.GetTableData().GetSectionData(SectionType.Body);

            var rowNumber   = 0;
            var rowToRemove = sectionData.FirstRowNumber;
            var rc          = sectionData.LastRowNumber - sectionData.FirstRowNumber;
            var sr          = sectionData.FirstRowNumber;

            for (var r = sr; r <= rc; r++)
            {
                using (var t = new SubTransaction(viewSchedule.Document))
                {
                    t.Start();

                    try
                    {
                        sectionData.RemoveRow(rowToRemove);

                        rowNumber++;

                        var elements = new FilteredElementCollector(viewSchedule.Document, viewSchedule.Id)
                                       .Where(e => e.IsValidObject && e.Category != null && e.Category.CategoryType != CategoryType.AnalyticalModel)
                                       .ToDictionary(e => e.Id.IntegerValue, e => e);

                        var elementsInRow = new RowData <int>(rowNumber);

                        var iterateCount = allElements.Count - elements.Count;
                        var iterateIndex = 0;
                        var keysToRemove = new List <int>();

                        foreach (var id in allElements)
                        {
                            if (!elements.ContainsKey(id))
                            {
                                elementsInRow.Items.Add(id);
                                keysToRemove.Add(id);
                                iterateIndex++;
                            }

                            if (iterateIndex == iterateCount)
                            {
                                break;
                            }
                        }

                        foreach (var key in keysToRemove)
                        {
                            allElements.Remove(key);
                        }

                        sortedElements.Add(elementsInRow);
                    }
                    catch (Exception exception)
                    {
                        Debug.Print($"Remove row {r}: {exception.Message}");
                        rowToRemove++;
                    }

                    t.Commit();
                }
            }

            return(sortedElements);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        public void SynchSheets(Document doc)
        {
            try
            {
                var centralPath = FileInfoUtil.GetCentralFilePath(doc);
                var sheetsData  = MissionControlSetup.SheetsData.ContainsKey(centralPath)
                    ? MissionControlSetup.SheetsData[centralPath]
                    : null;
                if (sheetsData == null)
                {
                    return;
                }

                var sheets = new FilteredElementCollector(doc)
                             .OfCategory(BuiltInCategory.OST_Sheets)
                             .WhereElementIsNotElementType()
                             .Cast <ViewSheet>()
                             .Select(x => new SheetItem(x, centralPath))
                             .ToDictionary(key => key.UniqueId, value => value);

                var revisions = new FilteredElementCollector(doc)
                                .OfCategory(BuiltInCategory.OST_Revisions)
                                .WhereElementIsNotElementType()
                                .Select(x => new RevisionItem(x))
                                .ToDictionary(key => key.UniqueId, value => value);

                var finalList = new List <SheetItem>();
                foreach (var ms in sheetsData.Sheets)
                {
                    if (sheets.ContainsKey(ms.UniqueId))
                    {
                        // sheet still exists in our model
                        // we can update it
                        var localSheet = sheets[ms.UniqueId];
                        localSheet.Tasks        = ms.Tasks;        // preserve mongo tasks
                        localSheet.Id           = ms.Id;           // preserve mongoIds
                        localSheet.CollectionId = ms.CollectionId; // preserve mongoIds

                        finalList.Add(localSheet);
                        sheets.Remove(ms.UniqueId);
                    }
                    else
                    {
                        // TODO: Something about this is not right. When a new sheet is added from the web interface, then approved in Revit and synched
                        var task = ms.Tasks.LastOrDefault();
                        if (task != null && task.IsNewSheet)
                        {
                            finalList.Add(ms); // this already has the ids
                        }
                        else
                        {
                            // sheet was deleted locally but still exists in mongo
                            ms.IsDeleted = true;
                            finalList.Add(ms);
                        }
                    }
                }
                finalList.AddRange(sheets.Values); // add whatever was not stored in mongo before

                var data = new SheetData
                {
                    CentralPath = centralPath.ToLower(),
                    Sheets      = finalList,
                    Revisions   = revisions.Values.ToList(),
                    Id          = sheetsData.Id
                };

                if (!ServerUtilities.Post(data, "sheets/" + sheetsData.Id,
                                          out SheetData unused))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to publish Sheets.");
                }

                if (MissionControlSetup.SheetsData.ContainsKey(centralPath))
                {
                    MissionControlSetup.SheetsData.Remove(centralPath);
                }
                MissionControlSetup.SheetsData.Add(centralPath, data); // store sheets record
            }
            catch (Exception e)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, e.Message);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="stylesId"></param>
        public void PublishData(Document doc, string stylesId)
        {
            try
            {
                _doc = doc;

                #region Text Note Type stats

                var textTypes = new FilteredElementCollector(doc)
                                .OfClass(typeof(TextNoteType))
                                .ToDictionary(x => x.Id.IntegerValue, x => new Tuple <Element, int>(x, 0));

                var textInstances = new FilteredElementCollector(doc)
                                    .OfClass(typeof(TextNote))
                                    .WhereElementIsNotElementType();

                foreach (var t in textInstances)
                {
                    var key = t.GetTypeId().IntegerValue;
                    if (textTypes.ContainsKey(key))
                    {
                        // increment instance count
                        textTypes[key] = new Tuple <Element, int>(textTypes[key].Item1, textTypes[key].Item2 + 1);
                    }
                }

                var textStats = textTypes.Select(x => new TextNoteTypeInfo(x.Value.Item1)
                {
                    Instances = x.Value.Item2
                })
                                .ToList();

                #endregion

                #region Dimension Type stats

                var dimTypes = new FilteredElementCollector(doc)
                               .OfClass(typeof(DimensionType))
                               .Cast <DimensionType>()
                               .Where(x => !string.IsNullOrEmpty(x.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()))
                               .ToDictionary(x => x.Id.IntegerValue, x => new Tuple <DimensionType, int>(x, 0));

                var dimInstances = new FilteredElementCollector(doc)
                                   .OfClass(typeof(Dimension))
                                   .WhereElementIsNotElementType()
                                   .Cast <Dimension>();

                // (Konrad) There is a user override in Configuration that controls what dimension overrides are ignored
                var centralPath = FileInfoUtil.GetCentralFilePath(doc);
                var config      = MissionControlSetup.Configurations.ContainsKey(centralPath)
                    ? MissionControlSetup.Configurations[centralPath]
                    : null;

                var dimensionValueCheck = new List <string> {
                    "EQ"
                };                                                   //defaults
                if (config != null)
                {
                    dimensionValueCheck = config.Updaters.First(x => string.Equals(x.UpdaterId,
                                                                                   Properties.Resources.HealthReportTrackerGuid, StringComparison.OrdinalIgnoreCase)).UserOverrides.DimensionValueCheck.Values;
                }

                var units           = _doc.GetUnits();
                var dimSegmentStats = new List <DimensionSegmentInfo>();
                foreach (var d in dimInstances)
                {
                    var key = d.GetTypeId().IntegerValue;
                    if (dimTypes.ContainsKey(key))
                    {
                        // increment instance count
                        dimTypes[key] = new Tuple <DimensionType, int>(dimTypes[key].Item1, dimTypes[key].Item2 + 1);
                    }

                    if (d.NumberOfSegments == 0)
                    {
                        if (string.IsNullOrEmpty(d.ValueOverride))
                        {
                            continue;
                        }
                        if (dimensionValueCheck.Any(d.ValueOverride.Contains))
                        {
                            continue;
                        }

                        // dim w/ zero segments
                        dimSegmentStats.Add(new DimensionSegmentInfo(d)
                        {
#if RELEASE2021
                            ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)d.Value, false),
#else
                            ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)d.Value, false, false),
#endif
                            OwnerViewType = d.ViewSpecific
                                ? ((View)doc.GetElement(d.OwnerViewId)).ViewType.ToString()
                                : string.Empty,
                            OwnerViewId = d.OwnerViewId.IntegerValue
                        });
                    }
                    else
                    {
                        // dim w/ multiple segments
                        foreach (DimensionSegment s in d.Segments)
                        {
                            if (string.IsNullOrEmpty(s.ValueOverride))
                            {
                                continue;
                            }
                            if (dimensionValueCheck.Any(s.ValueOverride.Contains))
                            {
                                continue;
                            }

                            dimSegmentStats.Add(new DimensionSegmentInfo(s)
                            {
#if RELEASE2021
                                ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)d.Value, false),
#else
                                ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)d.Value, false, false),
#endif
                                OwnerViewType = d.ViewSpecific
                                    ? ((View)doc.GetElement(d.OwnerViewId)).ViewType.ToString()
                                    : string.Empty,
                                OwnerViewId = d.OwnerViewId.IntegerValue
                            });
                        }
                    }
                }

                var dimStats = dimTypes.Select(x => new DimensionTypeInfo(x.Value.Item1)
                {
                    Instances = x.Value.Item2
                })
                               .ToList();

                #endregion

                #region Line Style stats

                //TODO: Finish this out.

                #endregion

                var stylesStats = new StylesDataItem
                {
                    User            = Environment.UserName.ToLower(),
                    TextStats       = textStats,
                    DimStats        = dimStats,
                    DimSegmentStats = dimSegmentStats
                };

                if (!ServerUtilities.Post(stylesStats, "styles/" + stylesId + "/stylestats",
                                          out StylesDataItem unused))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to publish Styles Data.");
                }
            }
            catch (Exception e)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, e.Message);
            }
        }