private DB.Transform GetTransform() { if (InternalElement.Document.GetHashCode() == DocumentManager.Instance.CurrentDBDocument.GetHashCode()) { return(DB.Transform.Identity); } else { //Find the revit instance where we find the room DB.FilteredElementCollector collector = new DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); List <DB.RevitLinkInstance> linkInstances = collector.OfCategory(DB.BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements().Cast <DB.RevitLinkInstance>().ToList(); DB.RevitLinkInstance roomLinkInstance = linkInstances.FirstOrDefault(); foreach (DB.RevitLinkInstance linkInstance in linkInstances) { if (linkInstance.GetLinkDocument().GetHashCode() == InternalElement.Document.GetHashCode()) { roomLinkInstance = linkInstance; break; } } return(roomLinkInstance.GetTotalTransform()); } }
public static List <global::Revit.Elements.Element> CopyElementsFromLinkedDocument(Autodesk.Revit.DB.Document sourceDocument, global::Revit.Elements.Element sourceInstance, List <global::Revit.Elements.Element> elements) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //converts elements to ids in a collection ICollection <ElementId> idCollection = new List <ElementId>(); foreach (global::Revit.Elements.Element element in elements) { idCollection.Add(element.InternalElement.Id); } Autodesk.Revit.DB.RevitLinkInstance internalInstance = (Autodesk.Revit.DB.RevitLinkInstance)sourceInstance.InternalElement; //creates blank copy paste options CopyPasteOptions copyOpts = new CopyPasteOptions(); //creates blank transform. Transform transform = Transform.CreateTranslation(Vector.XAxis().ToRevitType()); //commits the transaction TransactionManager.Instance.EnsureInTransaction(doc); ICollection <ElementId> newElementIds = ElementTransformUtils.CopyElements(sourceDocument, idCollection, doc, internalInstance.GetTransform(), copyOpts); TransactionManager.Instance.TransactionTaskDone(); //create a new list for the new elements List <global::Revit.Elements.Element> newElements = new List <global::Revit.Elements.Element>(); //gets the new elements foreach (ElementId id in newElementIds) { newElements.Add(doc.GetElement(id).ToDSType(true)); } return(newElements); }
public static List <global::Revit.Elements.Element> GetIntersectingElementsOfCategoryLinkOption(global::Revit.Elements.Element element, global::Revit.Elements.Category category, [DefaultArgument("Rhythm.Revit.Elements.Element.GetNull()")] global::Revit.Elements.Element sourceInstance) { //the current document Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //get built in category from user viewable category BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString()); //build a new list for the intersecting elements to be added to List <global::Revit.Elements.Element> intersectingElements = new List <global::Revit.Elements.Element>(); if (sourceInstance != null) { Autodesk.Revit.DB.RevitLinkInstance internalInstance = (Autodesk.Revit.DB.RevitLinkInstance)sourceInstance.InternalElement; //get the element's geometry. GeometryElement geomElement = element.InternalElement.get_Geometry(new Options()); //transform the solid to where the eff the link is. GeometryElement transformedElement = geomElement.GetTransformed(internalInstance.GetTransform()); //make a solid filter. Solid solid = null; foreach (GeometryObject geomObj in transformedElement) { solid = geomObj as Solid; if (solid != null) { break; } } //the intersection filter ElementIntersectsSolidFilter filter = new ElementIntersectsSolidFilter(solid); //build a collector FilteredElementCollector collector = new FilteredElementCollector(doc); //collect the elements that fall in that category IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList = collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements(); //add each user recognizable element to the list foreach (Autodesk.Revit.DB.Element internalElement in intersectingElementsInternaList) { intersectingElements.Add(internalElement.ToDSType(true)); } } else { //the intersection filter ElementIntersectsElementFilter filter = new ElementIntersectsElementFilter(element.InternalElement); //build a collector FilteredElementCollector collector = new FilteredElementCollector(doc); //collect the elements that fall in that category IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList = collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements(); //add each user recognizable element to the list foreach (Autodesk.Revit.DB.Element internalElement in intersectingElementsInternaList) { intersectingElements.Add(internalElement.ToDSType(true)); } } return(intersectingElements); }
/// <summary> /// Retrive family instance hosted in boundary elements /// This is the base function for Windows and Doors /// </summary> /// <param name="cat">The category of hosted elements</param> /// <returns></returns> private List <FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat) { List <FamilyInstance> output = new List <FamilyInstance>(); //the document of the room DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument; //Find boundary elements and their associated document List <DB.ElementId> boundaryElements = new List <DB.ElementId>(); List <DB.Document> boundaryDocuments = new List <DB.Document>(); foreach (DB.BoundarySegment segment in InternalBoundarySegments) { DB.Element boundaryElement = doc.GetElement(segment.ElementId); if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance)) { DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance; boundaryDocuments.Add(linkInstance.GetLinkDocument()); boundaryElements.Add(segment.LinkElementId); } else { boundaryDocuments.Add(doc); boundaryElements.Add(segment.ElementId); } } // Create a category filter DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat); // Apply the filter to the elements in these documents, // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents boundaryDocuments = boundaryDocuments.Distinct().ToList(); List <DB.FamilyInstance> familyInstances = new List <DB.FamilyInstance>(); foreach (DB.Document boundaryDocument in boundaryDocuments) { DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument); familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast <DB.FamilyInstance>().ToList()); } //Find all family instance hosted on a boundary element IEnumerable <DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id)); //loop on these boundary family instance to find to and from room foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances) { DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase; if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); continue; } } if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); } } } output = output.Distinct().ToList(); return(output); }
public RevitLinkInstance(DB.RevitLinkInstance instance) : base(instance) { }