public static object Wrap(Autodesk.Revit.DB.Panel ele, bool isRevitOwned) { if (AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(ele.Symbol)) { return(AdaptiveComponent.FromExisting(ele, isRevitOwned)); } return(CurtainPanel.FromExisting(ele, isRevitOwned)); }
public static AbstractFamilyInstance Wrap(Autodesk.Revit.DB.FamilyInstance ele, bool isRevitOwned) { if (AdaptiveComponentInstanceUtils.HasAdaptiveFamilySymbol(ele)) { return(AdaptiveComponent.FromExisting(ele, isRevitOwned)); } if (ele.StructuralType != Autodesk.Revit.DB.Structure.StructuralType.NonStructural) { return(StructuralFraming.FromExisting(ele, isRevitOwned)); } return(FamilyInstance.FromExisting(ele, isRevitOwned)); }
/// <summary> /// Create a list of adaptive components from two-dimensional array of points /// </summary> /// <param name="points">a two-dimensional array of points</param> /// <param name="familyType">a family type to use to create the adaptive components</param> /// <returns></returns> private static AdaptiveComponent[] InternalByPoints(Point[][] points, FamilyType familyType) { var oldInstances = ElementBinder.GetElementsFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); int countToBeCreated = points.Count(); int countOfOldInstances = 0; if (oldInstances != null) { countOfOldInstances = oldInstances.Count(); } int reusableCount = Math.Min(countToBeCreated, countOfOldInstances); TransactionManager.Instance.EnsureInTransaction(Document); List <Autodesk.Revit.DB.FamilyInstance> instances = new List <Autodesk.Revit.DB.FamilyInstance>(); List <AdaptiveComponent> components = new List <AdaptiveComponent>(); try { // Reuse the adaptive components that can be reused if possible for (int i = 0; i < reusableCount; i++) { var fi = oldInstances.ElementAt(i); var comp = new AdaptiveComponent(fi); components.Add(comp); //Update the family symbol if (familyType.InternalFamilySymbol.Id != fi.Symbol.Id) { fi.Symbol = familyType.InternalFamilySymbol; } UpdatePlacementPoints(fi, points[i].ToXyzs()); instances.Add(fi); } // Delete the redundant adaptive components if any for (int i = reusableCount; i < countOfOldInstances; i++) { var fi = oldInstances.ElementAt(i); Document.Delete(fi.Id); } // Create new adaptive components if (countToBeCreated > countOfOldInstances) { var remainingPoints = points.Skip(reusableCount).ToArray(); // Prepare the creation data for batch processing int numOfComponents = remainingPoints.Count(); List <FamilyInstanceCreationData> creationDatas = new List <FamilyInstanceCreationData>(numOfComponents); for (int i = 0; i < numOfComponents; ++i) { int numOfPoints = remainingPoints[i].Length; var aPoints = remainingPoints[i].ToXyzs(); var creationData = DocumentManager.Instance.CurrentUIApplication.Application.Create. NewFamilyInstanceCreationData(familyType.InternalFamilySymbol, aPoints); if (creationData != null) { creationDatas.Add(creationData); } } // Create elements based on the creation data in a batch ICollection <ElementId> elements; if (creationDatas.Count > 0) { if (Document.IsFamilyDocument) { elements = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewFamilyInstances2(creationDatas); } else { elements = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstances2(creationDatas); } foreach (var id in elements) { Autodesk.Revit.DB.FamilyInstance instance; if (ElementUtils.TryGetElement <Autodesk.Revit.DB.FamilyInstance>( DocumentManager.Instance.CurrentDBDocument, id, out instance)) { instances.Add(instance); components.Add(new AdaptiveComponent(instance)); } } } } ElementBinder.SetElementsForTrace(instances); } catch (Exception e) { // Unregister the elements from the element life cycle manager and delete the elements var elementManager = ElementIDLifecycleManager <int> .GetInstance(); foreach (var component in components) { elementManager.UnRegisterAssociation(component.InternalElementId.IntegerValue, component); } foreach (var instance in instances) { Document.Delete(instance.Id); } if (e is Autodesk.Revit.Exceptions.ArgumentException) { throw new ArgumentException("The arguments have issues", e); } else { throw e; } } finally { TransactionManager.Instance.TransactionTaskDone(); } return(components.ToArray()); }