Example #1
0
 public void OnToggleClick(FamilyItem item, bool value)
 {
     if (value)
     {
         Log.I("index: " + item.index);
     }
     Debug.Log("toggle change " + (value ? "On" : "Off"));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="family"></param>
        /// <returns></returns>
        public ObservableCollection <CheckWrapper> CollectChecks(FamilyItem family)
        {
            var config = MissionControlSetup.Configurations.ContainsKey(CentralPath)
                ? MissionControlSetup.Configurations[CentralPath]
                : null;

            var familyNameCheck = new List <string> {
                "HOK_I", "HOK_M"
            };                                                           //defaults

            if (config != null)
            {
                familyNameCheck = config.Updaters.First(x => string.Equals(x.UpdaterId,
                                                                           Resources.HealthReportTrackerGuid, StringComparison.OrdinalIgnoreCase)).UserOverrides.FamilyNameCheck.Values;
            }

            var output = new ObservableCollection <CheckWrapper>
            {
                new CheckWrapper
                {
                    CheckName      = $"Name: {family.Name}",
                    IsCheckPassing = familyNameCheck.Any(family.Name.Contains),
                    ToolTipText    = "Check will fail if Family name does not contain \"_HOK_I\" or \"_HOK_M\"."
                },
                new CheckWrapper
                {
                    CheckName      = $"Size: {family.Size}",
                    IsCheckPassing = family.SizeValue < 1000000,
                    ToolTipText    = "Check will fail if file size exceeds 1MB."
                },
                new CheckWrapper
                {
                    CheckName      = $"Instances: {family.Instances}",
                    IsCheckPassing = family.Instances > 0,
                    ToolTipText    = "Check will fail if Family has no placed instances."
                },
                new CheckWrapper
                {
                    CheckName      = $"Voids: {family.VoidCount}",
                    IsCheckPassing = family.VoidCount < 5,
                    ToolTipText    = "Check will fail if Family contains more than 5 void cuts."
                },
                new CheckWrapper
                {
                    CheckName      = $"Arrays: {family.ArrayCount}",
                    IsCheckPassing = family.ArrayCount < 5,
                    ToolTipText    = "Check will fail if Family contains more than 5 arrays."
                },
                new CheckWrapper
                {
                    CheckName      = $"Nested Families: {family.NestedFamilyCount}",
                    IsCheckPassing = family.NestedFamilyCount < 5,
                    ToolTipText    = "Check will fail if Family contains more than 5 nested families."
                }
            };

            return(output);
        }
Example #3
0
 public FamilyTaskWrapper(FamilyItem element, FamilyTask task)
 {
     Element = element;
     Task    = task;
 }
        /// <summary>
        /// Publishes information about linked models/images/object styles in the model.
        /// </summary>
        public void PublishData()
        {
            try
            {
                if (!MonitorUtilities.IsUpdaterOn(Project, Config, UpdaterGuid))
                {
                    return;
                }
                if (string.IsNullOrEmpty(FamiliesId))
                {
                    return;
                }

                var unusedFamilies    = 0;
                var oversizedFamilies = 0;
                var inPlaceFamilies   = 0;
                var families          = new FilteredElementCollector(Doc)
                                        .OfClass(typeof(Family))
                                        .Cast <Family>()
                                        .ToList();

                var config = MissionControlSetup.Configurations.ContainsKey(CentralPath)
                    ? MissionControlSetup.Configurations[CentralPath]
                    : null;

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

                //var count = 0;
                var famOutput = new List <FamilyItem>();
                StatusBarManager.InitializeProgress("Exporting Family Info:", families.Count);
                foreach (var family in families)
                {
                    // (Konrad) Uncomment for Debug.
                    //count++;
                    //if (count > 5) continue;
                    if (StatusBarManager.Cancel)
                    {
                        StatusBarManager.CancelProgress();
                        return;
                    }
                    StatusBarManager.StepForward();

                    var sizeCheck     = false;
                    var instanceCheck = false;
                    var nameCheck     = false;

                    var instances = CountFamilyInstances(family);
                    if (instances == 0)
                    {
                        unusedFamilies++;
                        instanceCheck = true;
                    }
                    if (family.IsInPlace)
                    {
                        inPlaceFamilies++;
                    }

                    long size           = 0;
                    var  refPlanes      = 0;
                    var  arrays         = 0;
                    var  voids          = 0;
                    var  nestedFamilies = 0;
                    var  parameters     = 0;
                    var  sizeStr        = "0Kb";
                    var  images         = 0;
                    try
                    {
                        var famDoc = Doc.EditFamily(family);

                        var storedPath = famDoc.PathName;
                        if (File.Exists(storedPath))
                        {
                            size = new FileInfo(storedPath).Length;
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(famDoc.Title))
                            {
                                continue;                                          // could cause an exception
                            }
                            var myDocPath = IsCitrixMachine(Environment.MachineName)
                                ? "B:\\Temp"
                                : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                            var path = myDocPath + "\\temp_" + famDoc.Title;
                            if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
                            {
                                continue;                                                    // could cause an exception
                            }
                            if (File.Exists(path))
                            {
                                TryToDelete(path);
                            }
                            famDoc.SaveAs(path);
                            size = new FileInfo(path).Length;
                            TryToDelete(path);
                        }

                        refPlanes = new FilteredElementCollector(famDoc)
                                    .OfClass(typeof(ReferencePlane))
                                    .GetElementCount();

                        var filter = new LogicalOrFilter(new List <ElementFilter>
                        {
                            new ElementClassFilter(typeof(LinearArray)),
                            new ElementClassFilter(typeof(RadialArray))
                        });

                        arrays = new FilteredElementCollector(famDoc)
                                 .WherePasses(filter)
                                 .GetElementCount();

                        images = new FilteredElementCollector(famDoc)
                                 .OfClass(typeof(ImageType))
                                 .WhereElementIsElementType()
                                 .GetElementCount();

                        voids = new FilteredElementCollector(famDoc)
                                .OfClass(typeof(Extrusion))
                                .Cast <Extrusion>()
                                .Count(x => !x.IsSolid);

                        nestedFamilies = new FilteredElementCollector(famDoc)
                                         .OfClass(typeof(Family))
                                         .GetElementCount();
#if RELEASE2015
                        //(Konrad) Since Revit 2015 API doesn't support this we will just skip it.
                        parameters = 0;
#else
                        parameters = new FilteredElementCollector(famDoc)
                                     .OfClass(typeof(ParameterElement))
                                     .GetElementCount();
#endif
                        famDoc.Close(false);

                        sizeStr = StringUtilities.BytesToString(size);
                        if (size > 1000000)
                        {
                            oversizedFamilies++; // >1MB
                            sizeCheck = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
                        Log.AppendLog(LogMessageType.ERROR, "Failed to retrieve size, refPlanes, arrays, voids...");
                    }

                    if (!familyNameCheck.Any(family.Name.Contains))
                    {
                        nameCheck = true;
                    }

                    var famItem = new FamilyItem
                    {
                        Name              = family.Name,
                        ElementId         = family.Id.IntegerValue,
                        Size              = sizeStr,
                        SizeValue         = size,
                        Instances         = instances,
                        ArrayCount        = arrays,
                        RefPlaneCount     = refPlanes,
                        VoidCount         = voids,
                        NestedFamilyCount = nestedFamilies,
                        ParametersCount   = parameters,
                        ImageCount        = images,
                        Tasks             = new List <FamilyTask>()
                    };

                    if (nameCheck || sizeCheck || instanceCheck)
                    {
                        famItem.IsFailingChecks = true;
                    }
                    else
                    {
                        famItem.IsFailingChecks = false;
                    }

                    famOutput.Add(famItem);
                }

                if (!ServerUtilities.GetByCentralPath(CentralPath, "families/centralpath", out FamilyData famStat))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to retrieve Families data.");
                    return;
                }

                var famDict = new Dictionary <string, FamilyItem>();
                if (famStat != null)
                {
                    famDict = famStat.Families.ToDictionary(x => x.Name, x => x);
                }

                // (Konrad) I know it's not efficient to iterate this list yet again, but
                // I want to minimize the amount of time between publishing families and
                // retrieving them from database to avoid someone addind tasks to DB while
                // we are exporting and hence losing them after the export.
                foreach (var family in famOutput)
                {
                    if (famDict.ContainsKey(family.Name))
                    {
                        family.Tasks.AddRange(famDict[family.Name].Tasks);
                        famDict.Remove(family.Name);
                    }
                }

                foreach (var item in famDict.Values.ToList())
                {
                    item.IsDeleted = true;
                    famOutput.Add(item);
                }

                var familyStats = new FamilyData
                {
                    CentralPath       = CentralPath.ToLower(),
                    TotalFamilies     = famOutput.Count,
                    UnusedFamilies    = unusedFamilies,
                    InPlaceFamilies   = inPlaceFamilies,
                    OversizedFamilies = oversizedFamilies,
                    CreatedBy         = Environment.UserName.ToLower(),
                    CreatedOn         = DateTime.UtcNow,
                    Families          = famOutput
                };

                if (!ServerUtilities.Put(familyStats, "families/" + famStat.Id))
                {
                    Log.AppendLog(LogMessageType.ERROR, "Failed to publish Families data.");
                }
                StatusBarManager.FinalizeProgress();
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="family"></param>
 public void EditFamily(FamilyItem family)
 {
     AppCommand.CommunicatorHandler.FamilyItem = family;
     AppCommand.CommunicatorHandler.Request.Make(RequestId.EditFamily);
     AppCommand.CommunicatorEvent.Raise();
 }