protected override void TrySolveInstance(IGH_DataAccess DA, DB.Document doc) { // grab wall system family from input var wallKind = DB.WallKind.Unknown; if (!DA.GetData("Wall System Family", ref wallKind)) { return; } // collect wall instances based on the given wallkind using (var collector = new DB.FilteredElementCollector(doc)) { IEnumerable <Types.Element> walls; if (wallKind == DB.WallKind.Basic) { walls = collector.OfClass(typeof(DB.Wall)) .Cast <DB.Wall>() .Where(x => x.WallType.Kind == wallKind && !x.IsStackedWallMember) .Select(x => Types.Element.FromElement(x)); } else { walls = collector.OfClass(typeof(DB.Wall)) .Where(x => ((DB.Wall)x).WallType.Kind == wallKind) .Select(x => Types.Element.FromElement(x)); } DA.SetDataList("Walls", walls); } }
public static IDictionary GetViewTemplates( [DefaultArgument("Synthetic.Revit.Document.Current()")] Autodesk.Revit.DB.Document doc ) { IList <ViewTemplate> templates = new List <ViewTemplate>(); IList <string> templateNames = new List <string>(); IList <revitDB.ElementId> templateIds = new List <revitDB.ElementId>(); if (doc != null) { revitDB.FilteredElementCollector collector = new revitDB.FilteredElementCollector(doc); List <revitDB.View> views = collector.OfClass(typeof(revitDB.View)) .Cast <revitDB.View>() .Where(view => view.IsTemplate) .Select(view => { templates.Add(new ViewTemplate(view)); templateNames.Add(view.Name); templateIds.Add(view.Id); return(view); }) .ToList <revitDB.View>(); } return(new Dictionary <string, object> { { "templates", templates }, { "template names", templateNames }, { "template IDs", templateIds } }); }
private void RefreshViewsList(ListBox listBox, DB.ViewFamily viewFamily) { var doc = Revit.ActiveUIDocument.Document; listBox.SelectedIndexChanged -= ListBox_SelectedIndexChanged; listBox.Items.Clear(); using (var collector = new DB.FilteredElementCollector(doc)) { var views = collector. OfClass(typeof(DB.View)). Cast <DB.View>(). Where(x => !x.IsTemplate). Where(x => viewFamily == DB.ViewFamily.Invalid || x.Document.GetElement <DB.ViewFamilyType>(x.GetTypeId())?.ViewFamily == viewFamily); listBox.DisplayMember = "DisplayName"; foreach (var view in views) { listBox.Items.Add(new Types.View(view)); } } listBox.SelectedIndex = listBox.Items.OfType <Types.View>().IndexOf(Current, 0).FirstOr(-1); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; }
private void InitializeListData() { if (null == m_wallTypeList || null == m_levelList) { throw new Exception("necessary data members don't initialize."); } RevitDB.Document document = m_commandData.Application.ActiveUIDocument.Document; RevitDB.FilteredElementCollector filteredElementCollector = new RevitDB.FilteredElementCollector(document); filteredElementCollector.OfClass(typeof(RevitDB.WallType)); m_wallTypeList = filteredElementCollector.Cast <RevitDB.WallType>().ToList <RevitDB.WallType>(); WallTypeComparer comparer = new WallTypeComparer(); m_wallTypeList.Sort(comparer); RevitDB.FilteredElementIterator iter = (new RevitDB.FilteredElementCollector(document)).OfClass(typeof(RevitDB.Level)).GetElementIterator(); iter.Reset(); while (iter.MoveNext()) { RevitDB.Level level = iter.Current as RevitDB.Level; if (null == level) { continue; } m_levelList.Add(level); } }
public static IEnumerable <Autodesk.Revit.DB.Level> GetAllLevels() { var collector = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); collector.OfClass(typeof(Autodesk.Revit.DB.Level)); return(collector.ToElements().Cast <Autodesk.Revit.DB.Level>()); }
protected override void Menu_AppendPromptOne(ToolStripDropDown menu) { if (SourceCount != 0) { return; } var listBox = new ListBox(); listBox.BorderStyle = BorderStyle.FixedSingle; listBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); listBox.Height = (int)(100 * GH_GraphicsUtil.UiScale); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; listBox.Sorted = true; var patternTargetBox = new ComboBox(); patternTargetBox.DropDownStyle = ComboBoxStyle.DropDownList; patternTargetBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); patternTargetBox.Tag = listBox; patternTargetBox.SelectedIndexChanged += PatternTargetBox_SelectedIndexChanged; patternTargetBox.SetCueBanner("Fill Pattern target filter…"); patternTargetBox.Sorted = true; using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { listBox.Items.Clear(); var patterns = collector. OfClass(typeof(DB.FillPatternElement)). Cast <DB.FillPatternElement>(). GroupBy(x => x.GetFillPattern().Target); foreach (var pattern in patterns) { patternTargetBox.Items.Add(pattern.Key); } if (Current?.Value is DB.FillPatternElement current) { var targetIndex = 0; foreach (var patternTarget in patternTargetBox.Items.Cast <DB.FillPatternTarget>()) { if (current.GetFillPattern().Target == patternTarget) { patternTargetBox.SelectedIndex = targetIndex; break; } targetIndex++; } } else { patternTargetBox.SelectedIndex = (int)DB.FillPatternTarget.Drafting; } } Menu_AppendCustomItem(menu, patternTargetBox); Menu_AppendCustomItem(menu, listBox); }
protected override void Menu_AppendPromptOne(ToolStripDropDown menu) { if (SourceCount != 0) { return; } var listBox = new ListBox(); listBox.BorderStyle = BorderStyle.FixedSingle; listBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); listBox.Height = (int)(100 * GH_GraphicsUtil.UiScale); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; listBox.Sorted = true; var materialCategoryBox = new ComboBox(); materialCategoryBox.DropDownStyle = ComboBoxStyle.DropDownList; materialCategoryBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); materialCategoryBox.Tag = listBox; materialCategoryBox.SelectedIndexChanged += MaterialCategoryBox_SelectedIndexChanged; materialCategoryBox.SetCueBanner("Material class filter…"); materialCategoryBox.Sorted = true; using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { listBox.Items.Clear(); var materials = collector. OfClass(typeof(DB.Material)). Cast <DB.Material>(). GroupBy(x => x.MaterialClass); foreach (var cat in materials) { materialCategoryBox.Items.Add(cat.Key); } if (Current?.Value is DB.Material current) { var familyIndex = 0; foreach (var materialClass in materialCategoryBox.Items.Cast <string>()) { if (current.MaterialClass == materialClass) { materialCategoryBox.SelectedIndex = familyIndex; break; } familyIndex++; } } else { RefreshMaterialsList(listBox, default); } } Menu_AppendCustomItem(menu, materialCategoryBox); Menu_AppendCustomItem(menu, listBox); }
static bool HasElementTypes(DB.ElementId categoryId) { using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { var elementCollector = collector.OfClass(typeof(R)).OfCategoryId(categoryId); return(elementCollector.GetElementCount() > 0); } }
public static Dictionary <string, DB.ElementId> GetMaterialIdsByName(DB.Document doc) { var collector = new DB.FilteredElementCollector(doc); return(collector.OfClass(typeof(DB.Material)).OfType <DB.Material>(). GroupBy(x => x.Name). ToDictionary(x => x.Key, x => x.First().Id)); }
/// <summary> /// Retrieve all materials in the document. /// </summary> /// <param name="document">>A Autodesk.Revit.DB.Document object. This does not work with Dynamo document objects.</param> /// <returns name="Materials">A list of Auotdesk.Revit.DB.Materials</returns> public static IEnumerable <RevitDB.Material> AllMaterials([DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document) { RevitFECollector collector = new RevitFECollector(document); return(collector .OfClass(typeof(RevitDB.Material)) .OfType <RevitDB.Material>()); }
internal static List <revitViewport> _renumberViewsOnSheet(FamilyType familyType, string xGridName, string yGridName, revitSheet rSheet, revitDoc document) { string transactionName = "Renumber views on sheet"; // Initialize variables revitFamilySymbol rFamilySymbol = (revitFamilySymbol)familyType.InternalElement; // Get all viewport ID's on the sheet. List <revitElemId> viewportIds = (List <revitElemId>)rSheet.GetAllViewports(); List <revitViewport> viewports = null; // Get the family Instances in view revitElemId symbolId = familyType.InternalElement.Id; revitCollector collector = new revitCollector(document, rSheet.Id); revitElementFilter filterInstance = new revitDB.FamilyInstanceFilter(document, symbolId); collector.OfClass(typeof(revitDB.FamilyInstance)).WherePasses(filterInstance); revitDB.FamilyInstance originFamily = (revitDB.FamilyInstance)collector.FirstElement(); // If family instance is found in the view // Then renumber views. if (originFamily != null) { revitDB.LocationPoint location = (revitDB.LocationPoint)originFamily.Location; revitXYZ originPoint = location.Point; double gridX = rFamilySymbol.LookupParameter(xGridName).AsDouble(); double gridY = rFamilySymbol.LookupParameter(yGridName).AsDouble(); // If the document is modifieable, // then a transaction is already open // and function uses the Dynamo Transaction Manager. // Else, open a new transaction. if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); viewports = View._tempRenumberViewports(viewportIds, document); viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start(transactionName); viewports = View._tempRenumberViewports(viewportIds, document); viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y); trans.Commit(); } } } return(viewports); }
public static Dictionary <string, object> AuditProjectFamilies(RevitDoc document, bool execute) { List <List <string> > results = new List <List <string> >(); List <List <string> > errors = new List <List <string> >(); if (execute) { RevitDB.FilteredElementCollector familyCollector = new RevitDB.FilteredElementCollector(document); familyCollector.OfClass(typeof(RevitDB.Family)).ToElements(); foreach (RevitDB.Family family in familyCollector) { List <string> familyResult = new List <string>(); familyResult.Add(family.Name); familyResult.Add(family.Id.ToString()); familyResult.Add(family.UniqueId); if (family.IsEditable) { try { var familyDoc = document.EditFamily(family); familyResult.Add("Opened successfully"); IList <RevitDB.FailureMessage> warnings = familyDoc.GetWarnings(); if (warnings.Count > 0) { StringBuilder warningString = new StringBuilder(); foreach (RevitDB.FailureMessage warning in warnings) { warningString.AppendLine(warning.GetDescriptionText()); } familyResult.Add(warningString.ToString()); } familyDoc.Close(false); } catch (Exception ex) { familyResult.Add("Error: " + ex.Message); errors.Add(familyResult); } results.Add(familyResult); } } } return(new Dictionary <string, object> { { "Results", results }, { "Errors", errors } }); }
protected override void TrySolveInstance(IGH_DataAccess DA, DB.Document doc) { using (var collector = new DB.FilteredElementCollector(doc)) { DA.SetDataList( "Linked Documents", // find all link instances in the model, and grab their source document reference collector.OfClass(typeof(DB.RevitLinkInstance)).Cast <DB.RevitLinkInstance>().Select(x => Types.Document.FromDocument(x.GetLinkDocument())) ); } }
public static RevitDB.Element RevitElementByNameClass(string Name, Type Class, [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document) { RevitFECollector collector = new RevitFECollector(document); RevitDB.Element elem = collector .OfClass(Class) .FirstOrDefault(e => e.Name.Equals(Name)); return(elem); }
private Autodesk.Revit.DB.FloorType GetFloorType(Document doc, string name) { var fec = new Autodesk.Revit.DB.FilteredElementCollector(doc); var floorType = fec.OfClass(typeof(Autodesk.Revit.DB.FloorType)) .Cast <Autodesk.Revit.DB.FloorType>() .First(x => x.Name == name); if (floorType == null) { throw new Exception($"The floor type, {name}, could not be found."); } return(floorType); }
/// <summary> /// Gets a material given its name and document /// </summary> /// <param name="Name">Name of a material</param> /// <param name="Document">Document to get the material from</param> /// <returns name="Material">A Autodeks.Revit.DB.Material</returns> public static revitMaterial GetByNameDocument(string Name, [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc Document) { revitDB.FilteredElementCollector collector = new revitDB.FilteredElementCollector(Document); collector .OfClass(typeof(revitDB.Material)) .OfType <revitDB.Material>(); return(collector .OfType <revitDB.Material>() .FirstOrDefault( m => m.Name.Equals(Name))); }
private void RefreshViewsList(ListBox listBox, DB.ViewType viewType) { var doc = Revit.ActiveUIDocument.Document; var selectedIndex = -1; try { listBox.SelectedIndexChanged -= ListBox_SelectedIndexChanged; listBox.Items.Clear(); var current = default(Types.View); if (SourceCount == 0 && PersistentDataCount == 1) { if (PersistentData.get_FirstItem(true) is Types.View firstValue) { current = firstValue.Duplicate() as Types.View; } } using (var collector = new DB.FilteredElementCollector(doc)) { var views = collector. OfClass(typeof(DB.View)). Cast <DB.View>(). Where(x => viewType == DB.ViewType.Undefined || x.ViewType == viewType); foreach (var view in views) { var tag = new Types.View(view); int index = listBox.Items.Add(tag.EmitProxy()); if (tag.UniqueID == current?.UniqueID) { selectedIndex = index; } } } } finally { listBox.SelectedIndex = selectedIndex; listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument != null) { using (var collector = new DB.FilteredElementCollector(Revit.ActiveDBDocument)) { foreach (var family in collector.OfClass(typeof(Autodesk.Revit.DB.Family)).Cast <Autodesk.Revit.DB.Family>().OrderBy((x) => $"{x.FamilyCategory.Name} : {x.Name}")) { var item = new GH_ValueListItem($"{family.FamilyCategory.Name} : {family.Name}", family.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument != null) { using (var collector = new DB.FilteredElementCollector(Revit.ActiveDBDocument)) { foreach (var level in collector.OfClass(typeof(DB.Level)).Cast <DB.Level>().OrderByDescending((x) => x.Elevation)) { var item = new GH_ValueListItem(level.Name, level.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument is DB.Document doc) { using (var collector = new DB.FilteredElementCollector(doc)) { foreach (var family in collector.OfClass(typeof(DB.Family)).Cast <DB.Family>().OrderBy((x) => $"{x.FamilyCategory.Name} : {x.Name}")) { var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), family.UniqueId); var item = new GH_ValueListItem($"{family.FamilyCategory.Name} : {family.Name}", $"\"{ referenceId }\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument is DB.Document doc) { using (var collector = new DB.FilteredElementCollector(doc)) { foreach (var level in collector.OfClass(typeof(DB.Level)).Cast <DB.Level>().OrderByDescending(x => x.GetHeight())) { var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), level.UniqueId); var item = new GH_ValueListItem(level.Name, $"\"{ referenceId }\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
/// <summary> /// Initialize a GroupType element from a set of objects ids and a name /// </summary> /// <param name="ids"></param> /// <param name="name"></param> private void InitGroupType(ICollection <DB.ElementId> ids, string name) { DB.Document document = DocumentManager.Instance.CurrentDBDocument; //Find all groupType name in the document DB.FilteredElementCollector collector = new DB.FilteredElementCollector(document); List <string> groupTypeNames = collector.OfClass(typeof(DB.GroupType)).ToElements().Select(element => element.Name).ToList(); // This creates a new wall and deletes the old one TransactionManager.Instance.EnsureInTransaction(document); //Phase 1 - Check to see if the object exists and should be rebound var GroupTypeElem = ElementBinder.GetElementFromTrace <DB.GroupType>(document); if (GroupTypeElem == null) { GroupTypeElem = document.Create.NewGroup(ids).GroupType; if (!groupTypeNames.Contains(name)) { GroupTypeElem.Name = name; } else { GetNextFilename(name + " {0}", groupTypeNames); } } InternalSetGroupType(GroupTypeElem); TransactionManager.Instance.TransactionTaskDone(); if (GroupTypeElem != null) { ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } }
public void GetFamilyInstancesByName() { var model = ViewModel.Model; string samplePath = Path.Combine(workingDirectory, @".\Family\GetFamilyInstancesByName.dyn"); string testPath = Path.GetFullPath(samplePath); ViewModel.OpenCommand.Execute(testPath); RunCurrentModel(); //get the number of loaded families in document: var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); fec.OfClass(typeof(Autodesk.Revit.DB.Family)); // obtain the family type with the provided name var families = fec.Cast <Autodesk.Revit.DB.Family>(); var oldcount = families.Count(); //find the node var node = this.Model.CurrentWorkspace.Nodes.Where(currentNode => currentNode.Name == "Family.ByName").FirstOrDefault(); Assert.IsNotNull(node); //now delete the node model.CurrentWorkspace.RemoveAndDisposeNode(node); //get the number of loaded families in document after removing the family.byname node from the graph: var fec2 = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); fec2.OfClass(typeof(Autodesk.Revit.DB.Family)); // obtain the family type with the provided name var families2 = fec2.Cast <Autodesk.Revit.DB.Family>(); var newcount = families.Count(); //now assert the families count is the same. Assert.AreEqual(oldcount, newcount); }
protected override void Menu_AppendPromptOne(ToolStripDropDown menu) { var listBox = new ListBox(); listBox.BorderStyle = BorderStyle.FixedSingle; listBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); listBox.Height = (int)(100 * GH_GraphicsUtil.UiScale); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; listBox.Sorted = true; var materialCategoryBox = new ComboBox(); materialCategoryBox.DropDownStyle = ComboBoxStyle.DropDownList; materialCategoryBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); materialCategoryBox.Tag = listBox; materialCategoryBox.SelectedIndexChanged += MaterialCategoryBox_SelectedIndexChanged; materialCategoryBox.SetCueBanner("Material class filter…"); using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { listBox.Items.Clear(); var materials = collector. OfClass(typeof(DB.Material)). Cast <DB.Material>(). GroupBy(x => x.MaterialClass); foreach (var cat in materials) { materialCategoryBox.Items.Add(cat.Key); } } RefreshMaterialsList(listBox, null); Menu_AppendCustomItem(menu, materialCategoryBox); Menu_AppendCustomItem(menu, listBox); }
protected override void Menu_AppendPromptOne(ToolStripDropDown menu) { var listBox = new ListBox(); listBox.BorderStyle = BorderStyle.FixedSingle; listBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); listBox.Height = (int)(100 * GH_GraphicsUtil.UiScale); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; listBox.Sorted = true; var viewTypeBox = new ComboBox(); viewTypeBox.DropDownStyle = ComboBoxStyle.DropDownList; viewTypeBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); viewTypeBox.Tag = listBox; viewTypeBox.SelectedIndexChanged += ViewTypeBox_SelectedIndexChanged; viewTypeBox.SetCueBanner("View type filter…"); using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { listBox.Items.Clear(); var views = collector. OfClass(typeof(DB.View)). Cast <DB.View>(). GroupBy(x => x.ViewType); foreach (var view in views) { viewTypeBox.Items.Add(view.Key); } } RefreshViewsList(listBox, DB.ViewType.Undefined); Menu_AppendCustomItem(menu, viewTypeBox); Menu_AppendCustomItem(menu, listBox); }
public static IDictionary GetLinkedRevit(RevitDoc document) { RevitDB.FilteredElementCollector links = new RevitDB.FilteredElementCollector(document); links.OfClass(typeof(RevitDB.RevitLinkInstance)); List <RevitDoc> linkDocs = new List <RevitDoc>(); List <string> linkNames = new List <string>(); foreach (RevitDB.RevitLinkInstance link in links) { RevitDoc linkDoc = link.GetLinkDocument(); linkDocs.Add(link.GetLinkDocument()); //document.GetElement(link.GetTypeId()); linkNames.Add(linkDoc.Title); } return(new Dictionary <string, object> { { "Documents", linkDocs }, { "Titles", linkNames } }); }
/// <summary> /// Retreives all view templates in a document. /// </summary> /// <param name="name">Name of the view template.</param> /// <param name="doc">Autodesk.Revit.DB.Document object.</param> /// <returns name="templates">View templates</returns> /// <returns name="template names">Names of the view templates</returns> /// <returns name="template IDs">Element IDs of the view templates</returns> public static ViewTemplate GetViewTemplateByName(string name, [DefaultArgument("Synthetic.Revit.Document.Current()")] Autodesk.Revit.DB.Document doc ) { ViewTemplate template = null; if (doc != null) { revitDB.FilteredElementCollector collector = new revitDB.FilteredElementCollector(doc); ICollection <revitDB.Element> views = collector.OfClass(typeof(revitDB.View)).ToElements(); foreach (revitDB.View view in views) { if (view.IsTemplate) { if (view.Name == name) { return(template = new ViewTemplate(view)); } } } } return(template); }
/// <summary> /// Initialize a GroupType element from a set of objects ids and a name /// </summary> /// <param name="ids"></param> /// <param name="name"></param> private void InitGroupType(ICollection<DB.ElementId> ids, string name) { DB.Document document = DocumentManager.Instance.CurrentDBDocument; //Find all groupType name in the document DB.FilteredElementCollector collector = new DB.FilteredElementCollector(document); List<string> groupTypeNames = collector.OfClass(typeof(DB.GroupType)).ToElements().Select(element => element.Name).ToList(); // This creates a new wall and deletes the old one TransactionManager.Instance.EnsureInTransaction(document); //Phase 1 - Check to see if the object exists and should be rebound var GroupTypeElem = ElementBinder.GetElementFromTrace<DB.GroupType>(document); if (GroupTypeElem == null) { GroupTypeElem = document.Create.NewGroup(ids).GroupType; if (!groupTypeNames.Contains(name)) { GroupTypeElem.Name = name; } else { GetNextFilename(name + " {0}", groupTypeNames); } } InternalSetGroupType(GroupTypeElem); TransactionManager.Instance.TransactionTaskDone(); if (GroupTypeElem != null) { ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } }
public static IEnumerable<Autodesk.Revit.DB.Level> GetAllLevels() { var collector = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); collector.OfClass(typeof(Autodesk.Revit.DB.Level)); return collector.ToElements().Cast<Autodesk.Revit.DB.Level>(); }
protected override void Menu_AppendPromptOne(ToolStripDropDown menu) { if (SourceCount != 0) { return; } var listBox = new ListBox(); listBox.BorderStyle = BorderStyle.FixedSingle; listBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); listBox.Height = (int)(100 * GH_GraphicsUtil.UiScale); listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; listBox.Sorted = true; var viewTypeBox = new ComboBox(); viewTypeBox.DropDownStyle = ComboBoxStyle.DropDownList; viewTypeBox.Width = (int)(200 * GH_GraphicsUtil.UiScale); viewTypeBox.Tag = listBox; viewTypeBox.SelectedIndexChanged += ViewTypeBox_SelectedIndexChanged; viewTypeBox.SetCueBanner("View type filter…"); using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document)) { listBox.Items.Clear(); var views = collector. OfClass(typeof(DB.View)). Cast <DB.View>(). Where(x => !x.IsTemplate). GroupBy(x => x.Document.GetElement <DB.ViewFamilyType>(x.GetTypeId())?.ViewFamily ?? DB.ViewFamily.Invalid); viewTypeBox.DisplayMember = "Text"; foreach (var view in views) { if (view.Key != DB.ViewFamily.Invalid) { viewTypeBox.Items.Add(new Types.ViewFamily(view.Key)); } } if (Current is Types.View current) { var familyIndex = 0; foreach (var viewFamily in viewTypeBox.Items.Cast <Types.ViewFamily>()) { var type = (DB.ViewFamilyType)current.Type; if (type.ViewFamily == viewFamily.Value) { viewTypeBox.SelectedIndex = familyIndex; break; } familyIndex++; } } else { RefreshViewsList(listBox, DB.ViewFamily.Invalid); } } Menu_AppendCustomItem(menu, viewTypeBox); Menu_AppendCustomItem(menu, listBox); }
protected override void TrySolveInstance(IGH_DataAccess DA) { DB.Element element = null; if (!DA.GetData("Element", ref element) || element is null) { return; } // Special cases if (element is DB.FamilyInstance familyInstace) { DA.SetData("Host", Types.HostObject.FromElement(familyInstace.Host)); return; } else if (element is DB.Opening opening) { DA.SetData("Host", Types.HostObject.FromElement(opening.Host)); return; } else if (element.get_Parameter(DB.BuiltInParameter.HOST_ID_PARAM) is DB.Parameter hostId) { DA.SetData("Host", Types.HostObject.FromElementId(element.Document, hostId.AsElementId())); return; } // Search geometrically if (element.get_BoundingBox(null) is DB.BoundingBoxXYZ bbox) { using (var collector = new DB.FilteredElementCollector(element.Document)) { var elementCollector = collector.OfClass(typeof(DB.HostObject)); if (element.Category.Parent is DB.Category hostCategory) { elementCollector = elementCollector.OfCategoryId(hostCategory.Id); } var bboxFilter = new DB.BoundingBoxIntersectsFilter(new DB.Outline(bbox.Min, bbox.Max)); elementCollector = elementCollector.WherePasses(bboxFilter); var classFilter = default(DB.ElementFilter); if (element is DB.FamilyInstance instance) { classFilter = new DB.FamilyInstanceFilter(element.Document, instance.GetTypeId()); } else if (element is DB.Area) { classFilter = new DB.AreaFilter(); } else if (element is DB.AreaTag) { classFilter = new DB.AreaTagFilter(); } else if (element is DB.Architecture.Room) { classFilter = new DB.Architecture.RoomFilter(); } else if (element is DB.Architecture.RoomTag) { classFilter = new DB.Architecture.RoomTagFilter(); } else if (element is DB.Mechanical.Space) { classFilter = new DB.Mechanical.SpaceFilter(); } else if (element is DB.Mechanical.SpaceTag) { classFilter = new DB.Mechanical.SpaceTagFilter(); } else { if (element is DB.CurveElement) { classFilter = new DB.ElementClassFilter(typeof(DB.CurveElement)); } else { classFilter = new DB.ElementClassFilter(element.GetType()); } } foreach (var host in elementCollector.Cast <DB.HostObject>()) { if (host.Id == element.Id) { continue; } if (host.FindInserts(false, true, true, false).Contains(element.Id)) { DA.SetData("Host", Types.HostObject.FromElement(host)); break; } // Necessary to found Panel walls in a Curtain Wall else if (host.GetDependentElements(classFilter).Contains(element.Id)) { DA.SetData("Host", Types.HostObject.FromElement(host)); break; } } } } }
public ADSK.FilteredElementCollector AddElementFilters(ADSK.FilteredElementCollector collector) { return(collector.OfClass(typeof(ADSK.Ceiling))); }