Ejemplo n.º 1
0
        //----------------------------------------------------------
        public void PurgeUnusedFamily(Document doc)
        {
            var           allElementsInView = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType().ToElements();
            List <string> familysName       = new List <string>();

            foreach (Element ele in allElementsInView)
            {
                string familyName = ele.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString();
                familysName.Add(familyName);
            }

            List <string> familysName_Unique = familysName.Distinct().ToList();
            List <string> familysName1       = new List <string>();

            var family = new FilteredElementCollector(doc).OfClass(typeof(Family)).ToList();
            List <ElementId> idDelete = new List <ElementId>();

            foreach (Family fa in family)
            {
                if (DocumentValidation.CanDeleteElement(doc, fa.Id) && familysName_Unique.Contains(fa.Name) == false)
                {
                    idDelete.Add(fa.Id);
                }
            }
            doc.Delete(idDelete);
        }
Ejemplo n.º 2
0
        public List <ElementId> FindAll2DElmentIds(ViewPlan view)
        {
            Document doc = view.Document;
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            List <ElementId>         ids       = collector.OwnedByView(view.Id).WhereElementIsNotElementType().ToElementIds().ToList();
            List <ElementId>         todelete  = new List <ElementId>();

            foreach (ElementId id in ids)
            {
                Element ele = doc.GetElement(id);
                if (!DocumentValidation.CanDeleteElement(doc, id))
                {
                    continue;
                }
                if (ele.Category == null)
                {
                    continue;
                }
                if (ele is ViewPlan)
                {
                    continue;
                }
                todelete.Add(id);
            }
            return(todelete);
        }
Ejemplo n.º 3
0
        //----------------------------------------------------------
        public void PurgeUnusedType(Document doc)
        {
            var           allElementsInView = new FilteredElementCollector(doc, doc.ActiveView.Id).ToElements();
            List <string> typesName         = new List <string>();
            List <string> familysName       = new List <string>();

            foreach (Element ele in allElementsInView)
            {
                typesName.Add(ele.Name);
                string familyName = ele.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString();
                familysName.Add(familyName);
            }

            List <string> typesName_Unique   = typesName.Distinct().ToList();
            List <string> familysName_Unique = familysName.Distinct().ToList();

            var elementType           = new FilteredElementCollector(doc).OfClass(typeof(ElementType)).ToList();
            var elementType1          = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).ToList();
            List <ElementId> idDelete = new List <ElementId>();

            foreach (ElementType type in elementType)
            {
                if (DocumentValidation.CanDeleteElement(doc, type.Id) && typesName_Unique.Contains(type.Name) == false && familysName_Unique.Contains(type.FamilyName))
                {
                    idDelete.Add(type.Id);
                }
            }
            foreach (FamilySymbol type in elementType1)
            {
                if (DocumentValidation.CanDeleteElement(doc, type.Id) && typesName_Unique.Contains(type.Name) == false && familysName_Unique.Contains(type.FamilyName))
                {
                    idDelete.Add(type.Id);
                }
            }
            foreach (ElementId type in idDelete)
            {
                Transaction            transaction = new Transaction(doc);
                FailureHandlingOptions failure     = transaction.GetFailureHandlingOptions();
                failure.SetClearAfterRollback(true);
                failure.SetForcedModalHandling(false);
                failure.SetFailuresPreprocessor(new RollbackIfErrorOccurs());
                transaction.SetFailureHandlingOptions(failure);
                transaction.Start("PurgeUnusedType");
                try
                {
                    doc.Delete(type);
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        //----------------------------------------------------------
        public void ClearElement(UIApplication uiapp, Document doc)
        {
            try
            {
                Transaction transaction = new Transaction(doc);
                transaction.Start("ClearElement");
                try
                {
                    List <ElementId> idDelete = new List <ElementId>();

                    if (option_normal.IsChecked == false)
                    {
                        data_by_level item = (data_by_level)level.SelectedItem;

                        foreach (var element in item.elements)
                        {
                            if (DocumentValidation.CanDeleteElement(doc, element.Id))
                            {
                                idDelete.Add(element.Id);
                            }
                        }
                        doc.Delete(idDelete);
                    }

                    PurgeUnusedFamily(doc);
                    PurgeUnusedMaterial(doc);

                    ChangeWallType(uiapp, doc);
                    ChangeFramingAndColumns(uiapp, doc);
                    RemoveFormwork(uiapp, doc);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    transaction.Dispose();
                }

                PurgeUnusedType(doc);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 5
0
 //----------------------------------------------------------
 public void DeleteView(UIApplication uiapp, Document doc)
 {
     try
     {
         Transaction tr = new Transaction(doc);
         tr.Start("DeleteView");
         var listLink1 = new FilteredElementCollector(doc).OfClass(typeof(CADLinkType)).ToElementIds();
         var listLink2 = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkType)).ToElementIds();
         var listLink3 = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast <View>().Where(x => DocumentValidation.CanDeleteElement(doc, x.Id)).Select(x => x.Id).ToList();
         doc.Delete(listLink1);
         doc.Delete(listLink2);
         doc.Delete(listLink3);
         tr.Commit();
     }
     catch (Exception)
     {
     }
 }