简体   繁体   English

如何在 Revit 中获取某个类别、类型和系列的所有元素

[英]How do I get all elements of a certain category, type and familiy in revit

I have a function where I would like to get all elements belonging to a certain category, type and family.我有一个函数,我想获取属于某个类别、类型和系列的所有元素。 I have their names as strings and would like to obtain the actual elements that meet the criteria.我将它们的名称作为字符串,并希望获得符合条件的实际元素。

I have tried a bit with the following:我尝试了以下内容:

    internal static void getElemetWithId(Document doc,string catName, string famname, string symbname)
    {

        Category category=null;
        foreach (var cat in  doc.Settings.Categories){
            if (((Category)cat).Name.Contains(catName))
            {
                category = (Category)cat;
                break;
            }
        }
        HashSet<Element> elements = new HashSet<Element>();
        elements.AddRange(GetFilteredElementCollector(doc, new ElementRetrievalOptions())
          .OfCategory(category).WhereElementIsElementType(famname).ToElements());
            }

However this doesn't work as OfCategory does not accept a Category as a argument (it does work for a builtInCategory) and WhereElementIsElementType does not seem to accept any argument.但是,这不起作用,因为 OfCategory 不接受 Category 作为参数(它确实适用于 builtInCategory)并且 WhereElementIsElementType 似乎不接受任何参数。

A possible input for this function would be document, "Doors" , "M_Single-Flush" , "0915 x 2134mm"这个函数的一个可能的输入是document, "Doors" , "M_Single-Flush" , "0915 x 2134mm"

You should look at the Revit SDK, http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16777469 , and go through some of the sample code.您应该查看 Revit SDK, http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16777469 ,并阅读一些示例代码。 You can also look at Jeremy's page: http://thebuildingcoder.typepad.com , and Harry's page: https://boostyourbim.wordpress.com for more sample code.您还可以查看 Jeremy 的页面: http : //thebuildingcoder.typepad.com和 Harry 的页面: https : //boostyourbim.wordpress.com以获取更多示例代码。

You should use the FilteredElementCollector Class to find all the Elements you'd be looking for:您应该使用 FilteredElementCollector 类来查找您要查找的所有元素:

FilteredElementCollector allInstances = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)‌​).Where(q => (q as FamilyInstance).Symbol.Name == symbname);

You can get all the elements belonging to the certain category using FilteredElementCollector class.您可以使用 FilteredElementCollector 类获取属于某个类别的所有元素。 Pass the name of the certain family name in the query and you will get all the elements of required family and type.在查询中传递特定姓氏的名称,您将获得所需家庭和类型的所有元素。 I have tried this on Revit 2019 recently.我最近在 Revit 2019 上尝试过这个。

List<Element> listOfElements = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).WhereElementIsElementType()
                .ToElements().Where(e => e.Name == elementName).ToList<Element>();

        ElementId symbolId = listOfElements[0].Id;

        FamilyInstanceFilter familyInstanceFilter= new FamilyInstanceFilter(doc, symbolId);
        IList<Element> familyInstances = new FilteredElementCollector(doc).WherePasses(familyInstanceFilter).ToElements();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM