public ScheduleUtil(Document doc, BuiltInCategory scheduleCategory, List<string> FieldsNames) { this.FieldsNames = FieldsNames; this.scheduleCategory = scheduleCategory; this.doc = doc; Schedule = null; }
private void CompareSliderCountAndMemberCount(BuiltInCategory cat, int sliderCount) { var slider = ViewModel.Model.AllNodes.FirstOrDefault(x => x is IntegerSlider) as IntegerSlider; slider.Value = sliderCount; RunCurrentModel(); var fec = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); fec.OfClass(typeof(FamilyInstance)).OfCategory(cat); Assert.AreEqual(slider.Value, fec.ToElements().Count); }
/// <summary> /// Given an Enumerable set of Elements, walk through them and filter out the ones of a specific /// category. /// </summary> /// <param name="filterForCategoryEnum">The BuiltInCategory enum to filter for</param> /// <param name="doc">The current Document object</param> /// <returns>The filtered ElementSet</returns> public static ElementSet FilterToCategory(BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) { ElementSet elemSet = new ElementSet(); FilteredElementCollector fec = new FilteredElementCollector(doc); ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(Element)); fec.WherePasses(elementsAreWanted); List<Element> elements = fec.ToElements() as List<Element>; foreach (Element element in elements) { elemSet.Insert(element); } return FilterToCategory(elemSet, filterForCategoryEnum, includeSymbols, doc); }
// 2016, jeremy /// <summary> /// Given an Enumerable set of Elements, walk through them and filter out the ones of a specific /// category. /// </summary> /// <param name="set">The unfiltered set</param> /// <param name="filterForCategoryEnum">The BuiltInCategory enum to filter for</param> /// <param name="doc">The current Document object</param> /// <returns>The filtered ElementSet</returns> //public static ElementSet //FilterToCategory(IEnumerable set, BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) // 2015, jeremy public static ICollection<ElementId> FilterToCategory( ICollection<ElementId> set, BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) { Category filterForCategory = doc.Settings.Categories.get_Item( filterForCategoryEnum ); Debug.Assert( filterForCategory != null ); //ElementSet filteredSet = new ElementSet(); //IEnumerator iter = set.GetEnumerator(); //while( iter.MoveNext() ) //{ // Element elem = (Element) iter.Current; // if( elem.Category == filterForCategory ) // { // if( includeSymbols ) // filteredSet.Insert( elem ); // include it no matter what // else // { // if( elem is ElementType == false ) // include it only if its not a symbol // filteredSet.Insert( elem ); // } // } //} //return filteredSet; List<ElementId> filteredSet = new List<ElementId>(); foreach(ElementId id in set ) { Element elem = doc.GetElement(id); if( elem.Category == filterForCategory ) { if( includeSymbols // include it no matter what || !(elem is ElementType) ) // include it only if its not a symbol { filteredSet.Add( id ); } } } return filteredSet; }
public static Category ById(int id) { try { var document = DocumentManager.Instance.CurrentDBDocument; BuiltInCategory categoryId = (BuiltInCategory)id; Autodesk.Revit.DB.Category category = Autodesk.Revit.DB.Category.GetCategory(document, categoryId); if (null == category) { throw new ArgumentException(Properties.Resources.InvalidCategory); } return(new Category(category)); } catch { throw new ArgumentException(Properties.Resources.InvalidCategory); } }
/// <summary> /// Return all families matching the given built-in category /// in the given document. Normally, one would simply use /// /// GetElementsOfType( doc, typeof( FamilyInstance ), bic ); /// /// Unfortunately, this does not work, because the Category /// property of families os often unimplemented, cf. /// http://thebuildingcoder.typepad.com/blog/2009/01/family-category-and-filtering.html /// and Clarify case 1258171 [Category filter problems]. /// </summary> public static IEnumerable <Family> GetFamilies( Document doc, BuiltInCategory bic) { FilteredElementCollector collector = new FilteredElementCollector(doc); //collector.OfCategory( bic ); // this does not work collector.OfClass(typeof(Family)); Category cat; IEnumerable <Element> familiesOfCategory = from f in collector where (null != (cat = FamilyCategory(f as Family)) && cat.Id.IntegerValue.Equals((int)bic)) select f; return(familiesOfCategory.Cast <Family>()); }
public static Category ById(int id) { try { var categories = DocumentManager.Instance.CurrentDBDocument.Settings.Categories; BuiltInCategory categoryId = (BuiltInCategory)id; Autodesk.Revit.DB.Category category = categories.get_Item(categoryId); if (null == category) { throw new ArgumentException(Properties.Resources.InvalidCategory); } return(new Category(category)); } catch { throw new ArgumentException(Properties.Resources.InvalidCategory); } }
private List <FamilyInstance> GetCategoryDevices(Document doc, Element wall, BuiltInCategory category) { BoundingBoxIntersectsFilter filter = Filter(wall, doc); List <FamilyInstance> list = new List <FamilyInstance>(); if (filter != null) { FilteredElementCollector collector = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(category) .WherePasses(filter); foreach (FamilyInstance instance in collector) { list.Add(instance); } } return(list); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; FamilyInstance beam = Util.SelectSingleElementOfType( uidoc, typeof(FamilyInstance), "a beam", false) as FamilyInstance; BuiltInCategory bic = BuiltInCategory.OST_StructuralFraming; if (null == beam || null == beam.Category || !beam.Category.Id.IntegerValue.Equals((int)bic)) { message = "Please select a single beam element."; } else { LocationCurve curve = beam.Location as LocationCurve; if (null == curve) { message = "No curve available"; return(Result.Failed); } XYZ p = curve.Curve.GetEndPoint(0); XYZ q = curve.Curve.GetEndPoint(1); XYZ v = 0.1 * (q - p); p = p - v; q = q + v; Creator creator = new Creator(doc); creator.CreateModelLine(p, q); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument _uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application; Autodesk.Revit.DB.Document _doc = _uidoc.Document; PlunkOClass plunkThis = new PlunkOClass(commandData.Application); BuiltInCategory _bicItemBeingRot = BuiltInCategory.OST_LightingFixtures; List <ElementId> _selIds; plunkThis.MatchRotationMany(_bicItemBeingRot, out _selIds); // _uidoc.Selection.SetElementIds(_selIds); return(Result.Succeeded); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static oM.Environment.Elements.PanelType?PanelType(this BuiltInCategory builtInCategory) { switch (builtInCategory) { case Autodesk.Revit.DB.BuiltInCategory.OST_Ceilings: return(oM.Environment.Elements.PanelType.Ceiling); case Autodesk.Revit.DB.BuiltInCategory.OST_Floors: return(oM.Environment.Elements.PanelType.Floor); case Autodesk.Revit.DB.BuiltInCategory.OST_Roofs: return(oM.Environment.Elements.PanelType.Roof); case Autodesk.Revit.DB.BuiltInCategory.OST_Walls: return(oM.Environment.Elements.PanelType.Wall); } return(null); }
public static PanelType PanelType(BuiltInCategory builtInCategory) { switch (builtInCategory) { case Autodesk.Revit.DB.BuiltInCategory.OST_Walls: return(Analytical.PanelType.Wall); case Autodesk.Revit.DB.BuiltInCategory.OST_Roofs: return(Analytical.PanelType.Roof); case Autodesk.Revit.DB.BuiltInCategory.OST_Floors: return(Analytical.PanelType.Floor); case Autodesk.Revit.DB.BuiltInCategory.OST_Ceilings: return(Analytical.PanelType.Ceiling); } return(Analytical.PanelType.Undefined); }
public void CreateSharedParameters(Document doc, Application app, BuiltInCategory builtInCategory, string groupName, string ParameterName) { Category Category = doc.Settings.Categories.get_Item(builtInCategory); CategorySet categorySet = app.Create.NewCategorySet(); categorySet.Insert(Category); string originalFile = app.SharedParametersFilename; string tempFile = @"X:\Revit\Revit Support\SOM-Structural Parameters.txt"; try { app.SharedParametersFilename = tempFile; DefinitionFile sharedParameterFile = app.OpenSharedParameterFile(); foreach (DefinitionGroup dg in sharedParameterFile.Groups) { if (dg.Name == groupName) { ExternalDefinition externalDefinition = dg.Definitions.get_Item(ParameterName) as ExternalDefinition; using (Transaction t = new Transaction(doc)) { t.Start("Add Translation Shared Parameters"); //parameter binding InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet); //parameter group to Identity Data in Revit Parameters doc.ParameterBindings.Insert(externalDefinition, newIB, BuiltInParameterGroup.PG_IDENTITY_DATA); doc.Regenerate(); t.Commit(); } } } } catch { } finally { //reset to original file app.SharedParametersFilename = originalFile; } }
public OverrideCat(Document doc, ElementId pattern, List <string> category_ovr) { BuiltInCategory category = Helper.GetCategories(category_ovr[0]); var r = Convert.ToByte(category_ovr[1]); var g = Convert.ToByte(category_ovr[2]); var b = Convert.ToByte(category_ovr[3]); var color_c = new Color(r, g, b); foreach (Category elem in doc.Settings.Categories) { try { if (elem != null) { var elemBcCat = (BuiltInCategory)elem.Id.IntegerValue; string bcCat = elemBcCat.ToString(); if (category_ovr[0] == bcCat) { this.categ = elem; } } } catch (Exception) { } } var gSettings = new OverrideGraphicSettings(); gSettings.SetSurfaceTransparency(0); gSettings.SetCutFillColor(color_c); gSettings.SetCutLineColor(color_c); gSettings.SetCutFillPatternVisible(true); gSettings.SetCutFillPatternId(pattern); gSettings.SetProjectionFillColor(color_c); gSettings.SetProjectionLineColor(color_c); gSettings.SetProjectionFillPatternId(pattern); this.builtincategory = category; this.overrides = gSettings; this.visible = true; }
public static Dictionary <string, object> IntersectionByElementCategoryFromLink(Revit.Elements.Category category, Document document = null, bool refresh = false) { List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>(); List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >(); string executed = ""; if (refresh) { BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true); Document doc = DocumentManager.Instance.CurrentDBDocument; //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); foreach (Autodesk.Revit.DB.Element e in collector) { List <Revit.Elements.Element> intersList = new List <Revit.Elements.Element>(); DynaFunctions f = new DynaFunctions(); ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e); FilteredElementCollector interElem = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType(); if (interElem.GetElementCount() > 0) { elList.Add(doc.GetElement(e.Id).ToDSType(true)); foreach (Autodesk.Revit.DB.Element el in interElem) { intersList.Add(document.GetElement(el.Id).ToDSType(true)); } inList.Add(intersList); } } } return(new Dictionary <string, object> { { "Elements", elList }, { "Intersections", inList }, { "Executed", executed } }); }
//***********************************GetFirstElement*********************************** private List <Element> GetElements(Document doc, BuiltInCategory category) { List <Element> elements = new List <Element>(); ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); // Category filter ElementCategoryFilter Categoryfilter = new ElementCategoryFilter(category); // Instance filter LogicalAndFilter InstancesFilter = new LogicalAndFilter(familyInstanceFilter, Categoryfilter); FilteredElementCollector collector = new FilteredElementCollector(doc); // Colletion Array of Elements ICollection <Element> Elements = collector.WherePasses(InstancesFilter).ToElements(); foreach (Element e in Elements) { elements.Add(e); } return(elements); }
protected virtual void ExtractObjects(MEPComponents mepComp) { MEPId mepId = null; int num = 0; try { mepId = MEPHelper.GetId(mepComp); num = mepId.builtInCategories.Count; } catch { } for (int i = 0; i < num; ++i) { BuiltInCategory bic = mepId.builtInCategories[i]; ElementType et = mepId.elementTypes[i]; FilteredElementCollector coll = new FilteredElementCollector(_doc); FamilyInstanceFilter fif = new FamilyInstanceFilter(_doc, et.Id); _equips.AddRange(coll.OfCategory(bic).WherePasses(fif).Cast <FamilyInstance>().ToList()); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument _uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application; Autodesk.Revit.DB.Document _doc = _uidoc.Document; PlunkOClass plunkThis = new PlunkOClass(commandData.Application); BuiltInCategory _bicItemDesired = BuiltInCategory.OST_DuctTerminal; List <ElementId> _selIds; plunkThis.PickTheseBicsOnly(_bicItemDesired, out _selIds); _uidoc.Selection.SetElementIds(_selIds); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; //Autodesk.Revit.UI.Selection.SelElementSet selElements = uidoc.Selection.Elements; ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds(); Element selecteedElement = null; foreach (ElementId e in selectedIds) { selecteedElement = uidoc.Document.GetElement(e); break; // just get one selected element } // Get the category instance from the Category property[從Category屬性中取得品類的實作元件] Category category = selecteedElement.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; TaskDialog.Show("王琪驊2019", "您所選取元件的品類名稱為:" + category.Name + "\n其對應的BuiltInCategory的名稱為:" + enumCategory); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { PlunkOClass plunkThis = new PlunkOClass(commandData.Application); string wsName = "MECH HVAC"; string FamilyTagName = "M_EQIP_BAS_SENSOR_TAG"; string FamilyTagNameSymb = "TAG NUMBER ONLY"; bool hasLeader = false; bool oneShot = false; BuiltInCategory bicTagBeing = BuiltInCategory.OST_MechanicalEquipmentTags; BuiltInCategory bicItemBeingTagged = BuiltInCategory.OST_MechanicalEquipment; Element elemTagged = null; string cmdPurpose = "Sensor Data"; Result res = plunkThis.TwoPickTag(wsName, FamilyTagName, FamilyTagNameSymb, bicItemBeingTagged, bicTagBeing, hasLeader, oneShot, ref elemTagged, cmdPurpose); return(Result.Succeeded); }
/// <summary> /// Gets the specified type and category of the element list. /// </summary> /// <param name="doc"></param> /// <param name="category"></param> /// <param name="viewId"></param> /// <returns></returns> public static List <T> GetInstanceElementList <T>(this Document doc, BuiltInCategory category, ElementId viewId = null) where T : Element { if (doc is null) { throw new ArgumentNullException(nameof(doc)); } var filter = new FilteredElementCollector(doc); if (viewId != null) { filter = new FilteredElementCollector(doc, viewId); } var catgFilter = filter.OfClass(typeof(T)).OfCategory(category); var instFilter = catgFilter.WhereElementIsNotElementType(); return(instFilter.Cast <T>().ToList()); }
/// <summary> /// Finds column elements which occur within a given set of references within the designated proximity, and stores them to the results. /// </summary> /// <param name="references">The references obtained from FindReferencesByDirection()</param> /// <param name="proximity">The maximum proximity.</param> /// <param name="wall">The wall from which these references were found.</param> private void FindColumnsWithin(IList <ReferenceWithContext> references, double proximity, Wall wall) { foreach (ReferenceWithContext reference in references) { // Exclude items too far from the start point. if (reference.Proximity < proximity) { Autodesk.Revit.DB.Element referenceElement = wall.Document.GetElement(reference.GetReference()); if (referenceElement is FamilyInstance) { FamilyInstance familyInstance = (FamilyInstance)referenceElement; ElementId familyInstanceId = familyInstance.Id; ElementId wallId = wall.Id; BuiltInCategory categoryValue = referenceElement.Category.BuiltInCategory; if (categoryValue == BuiltInCategory.OST_Columns || categoryValue == BuiltInCategory.OST_StructuralColumns) { // Add the column to the map of wall->columns if (m_columnsOnWall.ContainsKey(wallId)) { List <ElementId> columnsOnWall = m_columnsOnWall[wallId]; if (!columnsOnWall.Contains(familyInstanceId)) { columnsOnWall.Add(familyInstanceId); } } else { List <ElementId> columnsOnWall = new List <ElementId>(); columnsOnWall.Add(familyInstanceId); m_columnsOnWall.Add(wallId, columnsOnWall); } // Add the column to the complete list of all embedded columns if (!m_allColumnsOnWalls.Contains(familyInstanceId)) { m_allColumnsOnWalls.Add(familyInstanceId); } } } } } }
protected override Result ExecuteCommand(ExternalCommandData data, ref string message, ElementSet elements) { m_doc = data.Application.ActiveUIDocument.Document; var elems = new FilteredElementCollector(m_doc).OfClass(typeof(FamilyInstance)).ToList(); var categorys = elems.Select(x => x.Category).ToList(); categorys = categorys.Where((x, i) => categorys.FindIndex(z => z.Id == x.Id) == i).ToList(); string msg = ""; if (categorys?.Count > 0) { foreach (var cate in categorys) { msg += cate.Name + ":"; BuiltInCategory enumCategory = (BuiltInCategory)cate.Id.IntegerValue; //获取族 var familyList = new FilteredElementCollector(m_doc).OfCategory(enumCategory).OfClass(typeof(Family)).ToList(); if (familyList?.Count > 0) { //获取类型 var symbolList = new FilteredElementCollector(m_doc).OfCategory(enumCategory).OfClass(typeof(FamilySymbol)).ToList(); foreach (var family in familyList) { msg += family.Name + "-->"; var subSymbol = symbolList.FindAll(x => (x as FamilySymbol).Family.Id == family.Id); if (subSymbol?.Count > 0) { foreach (var symbol in subSymbol) { msg += symbol.Name + "-->"; var subIns = elems.FindAll(x => (x as FamilyInstance).Symbol.Id == symbol.Id); subIns.ForEach(x => msg += x.Name + ","); } } } } } TaskDialog.Show("结果", msg); } return(Result.Succeeded); }
//---------------------------------------------------------- public void Add_Category(Document doc, ComboBox category, All_Data myAll_Data) { try { my_category_data = new ObservableCollection <category_data>(); var builtin_category = Enum.GetValues(typeof(BuiltInCategory)).Cast <BuiltInCategory>().ToList(); var categories = doc.Settings.Categories; foreach (string name in myAll_Data.list_category_draw) { BuiltInCategory builtInCategory = BuiltInCategory.INVALID; foreach (BuiltInCategory buildCategory in builtin_category) { try { if (categories.get_Item(buildCategory) != null && categories.get_Item(buildCategory).Name == name) { builtInCategory = buildCategory; break; } } catch (Exception) { } } my_category_data.Add(new category_data() { single_value = name, builtin = builtInCategory }); } category.ItemsSource = my_category_data; category.SelectedIndex = 0; CollectionView view_category = (CollectionView)CollectionViewSource.GetDefaultView(category.ItemsSource); view_category.SortDescriptions.Add(new SortDescription("single_value", ListSortDirection.Ascending)); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes) { //Some of the legacy categories which were not working before will now be out of index. if (SelectedIndex < 0 || SelectedIndex >= Items.Count) { return new[] { AstFactory.BuildNullNode() } } ; BuiltInCategory categoryId = (BuiltInCategory)Items[SelectedIndex].Item; var args = new List <AssociativeNode> { AstFactory.BuildIntNode((int)categoryId) }; var func = new Func <int, Category>(Revit.Elements.Category.ById); var functionCall = AstFactory.BuildFunctionCall(func, args); return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) }); }
public void ShowCategoryName(Document document, ListBox listBox1) { Categories categories = document.Settings.Categories; Category cat; cat = categories.get_Item(Form1.selectedCategory); BuiltInCategory builtInCategory = (BuiltInCategory)cat.Id.IntegerValue; FilteredElementCollector collector = new FilteredElementCollector(document); IList <Element> elementsOfCategory = collector.WhereElementIsNotElementType().OfCategory(builtInCategory).ToElements(); Element el = elementsOfCategory.FirstOrDefault(); foreach (Parameter parameter in el.Parameters) { listBox1.Items.Add(parameter.Definition.Name); if (parameter.Definition.Name == ShowColumnCategory.uniqueParameter) { //TaskDialog.Show("cell value", parameter.Definition.Name + "/" + ShowColumnCategory.uniqueParameter); listBox1.Items.Remove(parameter.Definition.Name); } } }
/// <summary> /// Given an Enumerable set of Elements, walk through them and filter out the ones of a specific /// category. /// </summary> /// <param name="filterForCategoryEnum">The BuiltInCategory enum to filter for</param> /// <param name="doc">The current Document object</param> /// <returns>The filtered ElementSet</returns> //public static ElementSet FilterToCategory( BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc ) // 2015, jeremy public static ICollection <ElementId> FilterToCategory( BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) { //ElementSet elemSet = new ElementSet(); //FilteredElementCollector fec = new FilteredElementCollector( doc ); //ElementClassFilter elementsAreWanted = new ElementClassFilter( typeof( Element ) ); //fec.WherePasses( elementsAreWanted ); //List<Element> elements = fec.ToElements() as List<Element>; //foreach( Element element in elements ) //{ // elemSet.Insert( element ); //} //return FilterToCategory( elemSet, filterForCategoryEnum, includeSymbols, doc ); ICollection <ElementId> ids = new FilteredElementCollector(doc).OfClass(typeof(Element)).ToElementIds(); return(FilterToCategory(ids, filterForCategoryEnum, includeSymbols, doc)); }
private bool ValidateStructuralBeam(Element selectedBeam) { bool result = false; // Get the category instance from the Category property Category category = selectedBeam.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; if (enumCategory == BuiltInCategory.OST_StructuralFraming) { FamilyInstance beamAsInstance = selectedBeam as FamilyInstance; Parameter beamcutLength = beamAsInstance.LookupParameter("Cut Length"); if (beamAsInstance != null && beamcutLength != null) { result = true; } } return(result); }
//以下为各种method---------------------------------分割线--------------------------------- //获取目标模型组 public void getlistboxGroups(Document targetDoc, BuiltInCategory category) { IList <string> targetGroupNames = new List <string>();//目标文档中的模型/注释组列表 //获取目标文档详图组 IList <Element> MoDeGroups = (new FilteredElementCollector(targetDoc)).OfCategory(category).WhereElementIsNotElementType().ToElements(); targetGroupNames = getIlistNames(MoDeGroups);//获取详图组的string-list //组列表去重 targetGroupNames = targetGroupNames.Distinct().ToList(); CMD.selectedGroupNames = new List <string>(); //数据复原为空 this.listBox1.SelectedItems.Clear(); //数据复原为空 this.listBox1.Items.Clear(); //数据复原为空 foreach (string str in targetGroupNames) { this.listBox1.Items.Add(str); } }
//public static BuiltInCategory[] cats = //{ // BuiltInCategory.OST_Doors, // BuiltInCategory.OST_Walls, // BuiltInCategory.OST_Windows, // BuiltInCategory.OST_Furniture, // BuiltInCategory.OST_Levels, // BuiltInCategory.OST_Rooms, // BuiltInCategory.OST_MEPSpaces //}; public void ShowCategoryName(Document document, ListBox listBox1) { Categories categories = document.Settings.Categories; Category cat; cat = categories.get_Item(Form1.selectedCategory); BuiltInCategory builtInCategory = (BuiltInCategory)cat.Id.IntegerValue; FilteredElementCollector collector = new FilteredElementCollector(document); IList <Element> elementsOfCategory = collector.WhereElementIsNotElementType().OfCategory(builtInCategory).ToElements(); Element el = elementsOfCategory.FirstOrDefault(); foreach (Parameter parameter in el.Parameters) { listBox1.Items.Add(parameter.Definition.Name); } //izbjeci ovaj forech //foreach (BuiltInCategory bic in cats) //{ // try // { // cat = categories.get_Item(bic); // if (cat.Name == Form1.selectedCategory) // { // ElementCategoryFilter filter = new ElementCategoryFilter(bic); // FilteredElementCollector collector = new FilteredElementCollector(document); // List<Element> elem = collector.WherePasses(filter).WhereElementIsNotElementType().ToList(); // Element el = elem.FirstOrDefault(); // foreach (Parameter parameter in el.Parameters) // { // listBox1.Items.Add(parameter.Definition.Name); // } // } // } // catch (Exception ex) // { // TaskDialog.Show("wwwwww", ex.Message); // } //} //----------------------------------------------------------------------------------------------------------------- }
public static List <global::Revit.Elements.Element> IntersectingElementsInRoom(global::Revit.Elements.Room room, global::Revit.Elements.Category category) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.DesignScript.Geometry.Solid roomSolid = Autodesk.DesignScript.Geometry.Solid.ByUnion(room.Solids); //get built in category from user viewable category BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString()); //start the transaction TransactionManager.Instance.EnsureInTransaction(doc); //builds an id collection for later deletion ICollection <ElementId> idCollection = new List <ElementId>(); global::Revit.Elements.DirectShape directShape = global::Revit.Elements.DirectShape.ByGeometry(roomSolid, global::Revit.Elements.Category.ByName("Generic Models"), global::Revit.Elements.DirectShape.DynamoPreviewMaterial, "DirectShape"); idCollection.Add(directShape.InternalElement.Id); TransactionManager.Instance.TransactionTaskDone(); doc.Regenerate(); ElementIntersectsElementFilter filter = new ElementIntersectsElementFilter(directShape.InternalElement); //build a collector FilteredElementCollector collector = new FilteredElementCollector(doc); IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList = collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements(); //build a list to output geometry List <global::Revit.Elements.Element> intersectingElements = new List <global::Revit.Elements.Element>(); //append the intersecting elements to the output list foreach (Autodesk.Revit.DB.Element thing in intersectingElementsInternaList) { intersectingElements.Add(thing.ToDSType(true)); } //delete the direct shapes as we do not need them any longer TransactionManager.Instance.EnsureInTransaction(doc); foreach (ElementId id in idCollection) { doc.Delete(id); } TransactionManager.Instance.TransactionTaskDone(); return(intersectingElements); }
/***************************************************/ /**** Private Methods - Curve Based ****/ /***************************************************/ private static FamilyInstance FamilyInstance_TwoLevelsBased(Document document, FamilySymbol familySymbol, Curve curve, Element host, RevitSettings settings) { Line line = curve as Line; if (line == null) { familySymbol.LinearOnlyError(); return(null); } if (line.GetEndPoint(0).Z > line.GetEndPoint(1).Z) { familySymbol.InvalidTwoLevelLocationError(); return(null); } Level level = document.LevelBelow(line.GetEndPoint(0), settings); if (level == null) { return(null); } BuiltInCategory builtInCategory = (BuiltInCategory)familySymbol.Category.Id.IntegerValue; StructuralType structuralType = builtInCategory.StructuralType(); FamilyInstance familyInstance = document.Create.NewFamilyInstance(line, familySymbol, level, structuralType); if (familyInstance == null) { return(null); } if (host != null) { familyInstance.HostIgnoredWarning(); } return(familyInstance); }
public void BindParameter(Document document, Definition definition, BuiltInCategory category) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (definition == null) { throw new ArgumentNullException(nameof(definition)); } var app = document.Application; try { // create a category set and insert category of wall to it CategorySet myCategories = app.Create.NewCategorySet(); // use BuiltInCategory to get category of wall Category myCategory = Category.GetCategory(document, category); myCategories.Insert(myCategory); //Create an instance of InstanceBinding InstanceBinding instanceBinding = app.Create.NewInstanceBinding(myCategories); // Get the BingdingMap of current document. BindingMap bindingMap = document.ParameterBindings; // Bind the definitions to the document //bool instanceBindOK = bindingMap.Insert(parameter, instanceBinding, group); //var test = RegisterParameter("Piling", "Easting", ParameterType.Length, false, "Easting"); bool instanceBindOK = bindingMap.Insert(definition, instanceBinding); } catch (Exception e) { Debug.WriteLine(e.Message); } }
/// <summary> /// Reset categories CheckListBox control /// </summary> /// <param name="reAddAll">Indicates if it's needed to reset control with all applicable categories.</param> void ResetCategoriesControl(bool reAddAll) { m_catChangedEventSuppress = true; // suppress some events when checking categories during reset ICollection <BuiltInCategory> filterCat = m_currentFilterData.FilterCategories; if (hideUnCheckCheckBox.Checked) { categoryCheckedListBox.Items.Clear(); foreach (BuiltInCategory cat in filterCat) { String newCat = EnumParseUtility <BuiltInCategory> .Parse(cat); categoryCheckedListBox.Items.Add(newCat, true); } } else { // Add all items firstly if needed, happen when user plan to hide none if (reAddAll) { AddAppliableCategories(); } // // Check those categories of current filter for (int ii = 0; ii < categoryCheckedListBox.Items.Count; ii++) { // set all to unchecked firstly categoryCheckedListBox.SetItemChecked(ii, false); String catName = categoryCheckedListBox.Items[ii] as String; BuiltInCategory curCat = EnumParseUtility <BuiltInCategory> .Parse(catName); if (filterCat.Contains(curCat)) { categoryCheckedListBox.SetItemChecked(ii, true); } } } m_catChangedEventSuppress = false; }
/// <summary> /// Given an Enumerable set of Elements, walk through them and filter out the ones of a specific /// category. /// </summary> /// <param name="set">The unfiltered set</param> /// <param name="filterForCategoryEnum">The BuiltInCategory enum to filter for</param> /// <param name="doc">The current Document object</param> /// <returns>The filtered ElementSet</returns> public static ElementSet FilterToCategory(IEnumerable set, BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) { // get the Category filterForCategory = doc.Settings.Categories.get_Item(filterForCategoryEnum); Debug.Assert(filterForCategory != null); ElementSet filteredSet = new ElementSet(); IEnumerator iter = set.GetEnumerator(); while (iter.MoveNext()) { Element elem = (Element)iter.Current; if (elem.Category == filterForCategory) { if (includeSymbols) filteredSet.Insert(elem); // include it no matter what else { if (elem is ElementType == false) // include it only if its not a symbol filteredSet.Insert(elem); } } } return filteredSet; }
GetElementsOfType( Document doc, Type type, BuiltInCategory bic) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(bic); collector.OfClass(type); return collector; }
GetFamilySymbols( Document doc, BuiltInCategory bic) { return GetElementsOfType(doc, typeof(FamilySymbol), bic); }
/// <summary> /// Given an Enumerable set of Elements, walk through them and filter out the ones of a specific /// category. /// </summary> /// <param name="filterForCategoryEnum">The BuiltInCategory enum to filter for</param> /// <param name="doc">The current Document object</param> /// <returns>The filtered ElementSet</returns> //public static ElementSet FilterToCategory( BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc ) // 2015, jeremy public static ICollection<ElementId> FilterToCategory( BuiltInCategory filterForCategoryEnum, bool includeSymbols, Document doc) { //ElementSet elemSet = new ElementSet(); //FilteredElementCollector fec = new FilteredElementCollector( doc ); //ElementClassFilter elementsAreWanted = new ElementClassFilter( typeof( Element ) ); //fec.WherePasses( elementsAreWanted ); //List<Element> elements = fec.ToElements() as List<Element>; //foreach( Element element in elements ) //{ // elemSet.Insert( element ); //} //return FilterToCategory( elemSet, filterForCategoryEnum, includeSymbols, doc ); ICollection<ElementId> ids = new FilteredElementCollector( doc ).OfClass( typeof( Element ) ).ToElementIds(); return FilterToCategory( ids, filterForCategoryEnum, includeSymbols, doc ); }
/// <summary> /// get BuiltInCategoryFamily /// </summary> /// <param name="doc">document</param> /// <param name="cat">category</param> /// <returns></returns> public Dictionary<string, List<FamilySymbol>> FindFamilyTypes(Document doc, BuiltInCategory cat) { return new FilteredElementCollector(doc) .WherePasses(new ElementClassFilter(typeof(FamilySymbol))) .WherePasses(new ElementCategoryFilter(cat)) .Cast<FamilySymbol>() .GroupBy(e => e.Family.Name) .ToDictionary(e => e.Key, e => e.ToList()); }
/// <summary> /// Return true if the given built-in /// category supports instance parameters. /// </summary> static bool BicSupportsInstanceParameters( BuiltInCategory bic) { return _bicSupportsInstanceParameters.ContainsKey( bic ); }
public ICollection<Element> getElementsOfCategory(Document doc, BuiltInCategory cat, Type ty) { //Select all elements of type Wall. Ignore walltypes for now. ElementCategoryFilter Categoryfilter = new ElementCategoryFilter(cat); ElementClassFilter classFilter = new ElementClassFilter(ty); LogicalAndFilter InstancesFilter = new LogicalAndFilter(Categoryfilter, classFilter); FilteredElementCollector collector = new FilteredElementCollector(doc); return collector.WherePasses(InstancesFilter).ToElements(); }
/// <summary> /// Return all family symbols in the given document /// matching the given built-in category. /// Todo: Compare this with the FamilySymbolFilter class. /// </summary> static FilteredElementCollector GetFamilySymbols( Document doc, BuiltInCategory bic) { return GetElementsOfType( doc, typeof( FamilySymbol ), bic ); }
public List<FamilySymbol> GetSymbolsForCategory(BuiltInCategory category) { return new FilteredElementCollector(m_revitDoc.Document). OfCategory(category). OfClass(typeof(FamilySymbol)).OfType<FamilySymbol>().ToList(); }
/// <summary> /// Has the specific document shared parameter already been added ago? /// </summary> /// <param name="doc">Revit project in which the shared parameter will be added.</param> /// <param name="paraName">the name of the shared parameter.</param> /// <param name="boundCategory">Which category the parameter will bind to</param> /// <returns>Returns true if already added ago else returns false.</returns> private static bool AlreadyAddedSharedParameter(Document doc, string paraName, BuiltInCategory boundCategory) { try { BindingMap bindingMap = doc.ParameterBindings; DefinitionBindingMapIterator bindingMapIter = bindingMap.ForwardIterator(); while (bindingMapIter.MoveNext()) { if (bindingMapIter.Key.Name.Equals(paraName)) { ElementBinding binding = bindingMapIter.Current as ElementBinding; CategorySet categories = binding.Categories; foreach (Category category in categories) { if (category.Id.IntegerValue.Equals((int)boundCategory)) { return true; } } } } } catch (Exception) { return false; } return false; }
private static void AddCategories(Document doc, CategorySet myCategories, BuiltInCategory cat) { Category myCategory = doc.Settings.Categories.get_Item(cat); myCategories.Insert(myCategory); }
/// <summary> /// Return the element ids of all furniture and /// equipment family instances contained in the /// given room. /// </summary> static List<Element> GetFurniture( Room room ) { BoundingBoxXYZ bb = room.get_BoundingBox( null ); Outline outline = new Outline( bb.Min, bb.Max ); BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter( outline ); Document doc = room.Document; // Todo: add category filters and other // properties to narrow down the results // what categories of family instances // are we interested in? BuiltInCategory[] bics = new BuiltInCategory[] { BuiltInCategory.OST_Furniture, BuiltInCategory.OST_PlumbingFixtures, BuiltInCategory.OST_SpecialityEquipment }; LogicalOrFilter categoryFilter = new LogicalOrFilter( bics .Select<BuiltInCategory,ElementFilter>( bic => new ElementCategoryFilter( bic ) ) .ToList<ElementFilter>() ); FilteredElementCollector familyInstances = new FilteredElementCollector( doc ) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .OfClass( typeof( FamilyInstance ) ) .WherePasses( categoryFilter ) .WherePasses( filter ); int roomid = room.Id.IntegerValue; List<Element> a = new List<Element>(); foreach( FamilyInstance fi in familyInstances ) { if( null != fi.Room && fi.Room.Id.IntegerValue.Equals( roomid ) ) { Debug.Assert( fi.Location is LocationPoint, "expected all furniture to have a location point" ); a.Add( fi ); } } return a; }
/// <summary> /// Retrieve all standard family instances for a given category. /// Todo: Compare this with the FamilyInstanceFilter class. /// </summary> public static FilteredElementCollector GetFamilyInstances( Document doc, BuiltInCategory bic) { /* 2009: List<Element> elements = new List<Element>(); Filter filterType = app.Create.Filter.NewTypeFilter( typeof( FamilyInstance ) ); Filter filterCategory = app.Create.Filter.NewCategoryFilter( bic ); Filter filterAnd = app.Create.Filter.NewLogicAndFilter( filterType, filterCategory ); app.ActiveDocument.get_Elements( filterAnd, elements ); return elements; */ return GetElementsOfType( doc, typeof( FamilyInstance ), bic ); }
/// <summary> /// Return all families matching the given built-in category /// in the given document. Normally, one would simply use /// /// GetElementsOfType( doc, typeof( FamilyInstance ), bic ); /// /// Unfortunately, this does not work, because the Category /// property of families os often unimplemented, cf. /// http://thebuildingcoder.typepad.com/blog/2009/01/family-category-and-filtering.html /// and Clarify case 1258171 [Category filter problems]. /// </summary> public static IEnumerable<Family> GetFamilies( Document doc, BuiltInCategory bic) { FilteredElementCollector collector = new FilteredElementCollector( doc ); //collector.OfCategory( bic ); // this does not work collector.OfClass( typeof( Family ) ); Category cat; IEnumerable<Element> familiesOfCategory = from f in collector where ( null != ( cat = FamilyCategory( f as Family ) ) && cat.Id.IntegerValue.Equals( (int) bic ) ) select f; return familiesOfCategory.Cast<Family>(); }
/// <summary> /// Return the first family symbol found in the given document /// matching the given built-in category or null if none is found. /// </summary> public static FamilySymbol GetFirstFamilySymbol( Document doc, BuiltInCategory bic) { FamilySymbol s = GetFamilySymbols(doc, bic).FirstElement() as FamilySymbol; Debug.Assert(null != s, string.Format( "expected at least one {0} symbol in project", bic.ToString())); return s; }
/// <summary> /// Gets a Family by its Category, Family name and Type Name /// </summary> /// <param name="document"></param> /// <param name="category">Category</param> /// <param name="family">Family Name</param> /// <param name="type">Type Name</param> /// <returns></returns> public static Element GetElementByName(this Document document, BuiltInCategory category, string family, string type) { FilteredElementCollector collector = new FilteredElementCollector(document).OfCategory(category); foreach (Element e in collector.ToElements()) { string familyName = ""; string typeName = ""; if (e.GetType() == typeof(FamilyInstance)) { FamilyInstance fi = (FamilyInstance)e; familyName = fi.Symbol.Family.Name; typeName = fi.Symbol.Name; } else if (e.GetType() == typeof(FamilySymbol)) { FamilySymbol fs = (FamilySymbol)e; familyName = fs.Family.Name; typeName = fs.Name; } if (familyName == family && typeName == type) return e; } return collector.FirstElement(); }
// ============================================ // (0) check if we have a correct template // ============================================ bool isRightTemplate(BuiltInCategory targetCategory) { // This command works in the context of family editor only. // if (!_doc.IsFamilyDocument) { Util.ErrorMsg("This command works only in the family editor."); return false; } // Check the template for an appropriate category here if needed. // Category cat = _doc.Settings.Categories.get_Item(targetCategory); if (_doc.OwnerFamily == null) { Util.ErrorMsg("This command only works in the family context."); return false; } if (!cat.Id.Equals(_doc.OwnerFamily.FamilyCategory.Id)) { Util.ErrorMsg("Category of this family document does not match the context required by this command."); return false; } // if we come here, we should have a right one. return true; }
Category GetCategory( Document doc, BuiltInCategory target) { Category cat = null; if( target.Equals( BuiltInCategory.OST_IOSModelGroups ) ) { // determine model group category: FilteredElementCollector collector = Util.GetElementsOfType( doc, typeof( Group ), // GroupType works as well BuiltInCategory.OST_IOSModelGroups ); IList<Element> modelGroups = collector.ToElements(); if( 0 == modelGroups.Count ) { Util.ErrorMsg( "Please insert a model group." ); return cat; } else { cat = modelGroups[0].Category; } } else { try { cat = doc.Settings.Categories.get_Item( target ); } catch( Exception ex ) { Util.ErrorMsg( string.Format( "Error obtaining document {0} category: {1}", target.ToString(), ex.Message ) ); return cat; } } if( null == cat ) { Util.ErrorMsg( string.Format( "Unable to obtain the document {0} category.", target.ToString() ) ); } return cat; }