public static Log Log(ApertureConstruction apertureConstruction, Document document) { if (apertureConstruction == null || document == null) { return(null); } Log result = new Log(); Core.Modify.AddRange(result, Core.Revit.Create.Log(apertureConstruction, document)); string name = apertureConstruction.Name; if (string.IsNullOrWhiteSpace(name)) { result.Add("ApertureConstruction has invalid name Guid: {0}", LogRecordType.Error, apertureConstruction.Guid); return(result); } BuiltInCategory builtInCategory = apertureConstruction.BuiltInCategory(); if (builtInCategory == BuiltInCategory.INVALID) { result.Add("Could not get BuiltInCategory from ApertureConstruction Guid: {0}, Name: {1}", LogRecordType.Error, apertureConstruction.Guid, apertureConstruction.Name); return(result); } List <FamilySymbol> familySymbols = new FilteredElementCollector(document).OfClass(typeof(FamilySymbol)).OfCategory(builtInCategory).Cast <FamilySymbol>().ToList(); if (familySymbols != null && familySymbols.Count != 0) { foreach (FamilySymbol familySymbol in familySymbols) { string fullName = Core.Revit.Query.FullName(familySymbol); if (apertureConstruction.Name.Equals(fullName) || apertureConstruction.Name.Equals(familySymbol.Name)) { return(result); } } } result.Add("Could not find Revit FamilyType Name: {1} for ApertureConstruction Guid: {0}", LogRecordType.Error, apertureConstruction.Guid, apertureConstruction.Name); return(result); }
public static ElementType DuplicateByName(this Document document, string name_Old, ApertureConstruction apertureConstruction_New, IEnumerable <string> parameterNames = null) { if (apertureConstruction_New == null || document == null || string.IsNullOrWhiteSpace(name_Old)) { return(null); } ElementType result = Core.Revit.Modify.DuplicateByName(document, name_Old, apertureConstruction_New.BuiltInCategory(), apertureConstruction_New, parameterNames); if (result == null) { return(null); } Core.Revit.Modify.SetValues(result, apertureConstruction_New, ActiveSetting.Setting, null, parameterNames); return(result); }
public static FamilySymbol ToRevit(this ApertureConstruction apertureConstruction, Document document, Core.Revit.ConvertSettings convertSettings) { if (apertureConstruction == null) { return(null); } FamilySymbol result = convertSettings?.GetObject <FamilySymbol>(apertureConstruction.Guid); if (result != null) { return(result); } string fullName = apertureConstruction.Name; string familyName; string familyTypeName; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(fullName, out familyName, out familyTypeName)) { return(null); } List <BuiltInCategory> builtInCategories = new List <BuiltInCategory>(); BuiltInCategory builtInCategory = apertureConstruction.BuiltInCategory(); if (builtInCategory == BuiltInCategory.INVALID) { builtInCategories.Add(Query.BuiltInCategory(ApertureType.Door)); builtInCategories.Add(Query.BuiltInCategory(ApertureType.Window)); } else { builtInCategories.Add(builtInCategory); } List <FamilySymbol> familySymbols = new FilteredElementCollector(document).OfClass(typeof(FamilySymbol)).WherePasses(new LogicalOrFilter(builtInCategories.ConvertAll(x => new ElementCategoryFilter(x) as ElementFilter))).Cast <FamilySymbol>().ToList(); if (familySymbols == null || familySymbols.Count == 0) { return(null); } familySymbols.RemoveAll(x => string.IsNullOrWhiteSpace(x.Name) || !x.Name.Equals(familyTypeName)); if (!string.IsNullOrWhiteSpace(familyName)) { familySymbols.RemoveAll(x => string.IsNullOrWhiteSpace(x.FamilyName) || !x.FamilyName.Equals(familyName)); } familySymbols.RemoveAll(x => x.Family == null && x.Family.FamilyPlacementType != FamilyPlacementType.OneLevelBasedHosted); if (familySymbols.Count == 0) { return(null); } result = familySymbols.First(); if (result == null) { return(null); } if (!result.IsActive) { result.Activate(); } convertSettings?.Add(apertureConstruction.Guid, result); return(result); }