public static ClonedType CloneType(this IBHoMObject sourceRevitObject, string newName) { if (sourceRevitObject == null) { BH.Engine.Reflection.Compute.RecordError("It is impossible to clone a null Revit object."); return null; } RevitIdentifiers identifiers = sourceRevitObject.FindFragment<RevitIdentifiers>(); if (identifiers == null) { BH.Engine.Reflection.Compute.RecordError("The input object is not a valid pulled Revit element."); return null; } ClonedType result = new ClonedType { SourceTypeId = identifiers.FamilyTypeId, Name = newName }; if (identifiers.ElementId == identifiers.FamilyTypeId) { RevitParametersToPush parametersToPush = sourceRevitObject.FindFragment<RevitParametersToPush>(); if (parametersToPush != null) { BH.Engine.Reflection.Compute.RecordWarning("Parameters to push have been cloned from the source Revit type object."); result.AddFragment(parametersToPush.DeepClone()); } } else BH.Engine.Reflection.Compute.RecordWarning("The input object is a pulled Revit element, its type has been cloned."); return result; }
/***************************************************/ public static ElementType ToRevitElementType(this ClonedType clonedType, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { ElementType elementType = refObjects.GetValue <ElementType>(document, clonedType.BHoM_Guid); if (elementType != null) { return(elementType); } settings = settings.DefaultIfNull(); Element source = document.GetElement(new ElementId(clonedType.SourceTypeId)); if (source == null) { BH.Engine.Reflection.Compute.RecordError($"The element with ElementId {clonedType.SourceTypeId} does not exist in the active Revit document."); return(null); } ElementType sourceType = source as ElementType; if (sourceType == null) { BH.Engine.Reflection.Compute.RecordError($"The element with ElementId {clonedType.SourceTypeId} exists in the active Revit document, but it is not an element type."); return(null); } elementType = sourceType.Duplicate(clonedType.Name); // Copy parameters from BHoM object to Revit element elementType.CopyParameters(clonedType, settings); refObjects.AddOrReplace(clonedType, elementType); return(elementType); }
/***************************************************/ public static Element ToRevit(this ClonedType clonedType, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { return(clonedType.ToRevitElementType(document, settings, refObjects)); }