/// <summary> /// delete elements depends on the input params.json file /// </summary> /// <param name="data"></param> public void DeleteAllElements(DesignAutomationData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } Application rvtApp = data.RevitApp; if (rvtApp == null) { throw new InvalidDataException(nameof(rvtApp)); } string modelPath = data.FilePath; if (String.IsNullOrWhiteSpace(modelPath)) { throw new InvalidDataException(nameof(modelPath)); } _doc = data.RevitDoc; if (_doc == null) { throw new InvalidOperationException("Could not open document."); } _tt = new Transaction(_doc, "Generate Facades"); countItParams = DeleteElementsParams.Parse("params.json"); GenerateFacade(); ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt"); _doc.SaveAs(path, new SaveAsOptions()); }
/// <summary> /// delete elements depends on the input params.json file /// </summary> /// <param name="data"></param> public static void DeleteAllElements(DesignAutomationData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } Application rvtApp = data.RevitApp; if (rvtApp == null) { throw new InvalidDataException(nameof(rvtApp)); } string modelPath = data.FilePath; if (String.IsNullOrWhiteSpace(modelPath)) { throw new InvalidDataException(nameof(modelPath)); } // If the input revit model passed is a workshared revit file then by default the Design Automation // bridge will open the model detached from central, opting DetachAndPreserveWorsets option. // Non-worshared revit file will be load as is. Document doc = data.RevitDoc; if (doc == null) { throw new InvalidOperationException("Could not open document."); } // For CountIt workItem: If RvtParameters is null, count all types DeleteElementsParams deleteElementsParams = DeleteElementsParams.Parse("params.json"); using (Transaction transaction = new Transaction(doc)) { transaction.Start("Delete Elements"); if (deleteElementsParams.walls) { FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(Wall)); doc.Delete(col.ToElementIds()); } if (deleteElementsParams.floors) { FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(Floor)); doc.Delete(col.ToElementIds()); } if (deleteElementsParams.doors) { FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection <ElementId> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Doors) .ToElementIds(); doc.Delete(collection); } if (deleteElementsParams.windows) { FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection <ElementId> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Windows) .ToElementIds(); doc.Delete(collection); } transaction.Commit(); } ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt"); // If a worshared file is opened as a part of this addin then the new file will be // saved as central. SaveAsOptions opts = new SaveAsOptions(); if (doc.IsWorkshared) { opts.SetWorksharingOptions(new WorksharingSaveAsOptions { SaveAsCentral = true }); WorksharingUtils.RelinquishOwnership(doc, new RelinquishOptions(true), new TransactWithCentralOptions()); } doc.SaveAs(path, new SaveAsOptions()); }
/// <summary> /// delete elements depends on the input params.json file /// </summary> /// <param name="data"></param> public static void DeleteAllElements(DesignAutomationData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } Application rvtApp = data.RevitApp; if (rvtApp == null) { throw new InvalidDataException(nameof(rvtApp)); } string modelPath = data.FilePath; if (String.IsNullOrWhiteSpace(modelPath)) { throw new InvalidDataException(nameof(modelPath)); } Document doc = data.RevitDoc; if (doc == null) { throw new InvalidOperationException("Could not open document."); } // For CountIt workItem: If RvtParameters is null, count all types DeleteElementsParams deleteElementsParams = DeleteElementsParams.Parse("params.json"); using (Transaction transaction = new Transaction(doc)) { transaction.Start("Delete Elements"); if (deleteElementsParams.walls) { FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(Wall)); doc.Delete(col.ToElementIds()); } if (deleteElementsParams.columns) { FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(Column)); doc.Delete(col.ToElementIds()); } if (deleteElementsParams.floors) { FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(Floor)); doc.Delete(col.ToElementIds()); } if (deleteElementsParams.doors) { FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection <ElementId> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Doors) .ToElementIds(); doc.Delete(collection); } if (deleteElementsParams.windows) { FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection <ElementId> collection = collector.OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_Windows) .ToElementIds(); doc.Delete(collection); } transaction.Commit(); } ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt"); doc.SaveAs(path, new SaveAsOptions()); }