【问题标题】:Revit - Apply divided surface to wallsRevit - 将分割的表面应用于墙壁
【发布时间】:2021-12-28 20:53:42
【问题描述】:

我编写了一个程序,该程序使用对形状的面的引用来形成一个分割的表面。但是当应用于墙壁时(带有类别选择的搜索字符串在下面突出显示),程序什么也不做。如何将此程序仅应用于项目中的所有墙壁?

   public class Command : IExternalCommand
    {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document doc = app.ActiveUIDocument.Document;

            Autodesk.Revit.Creation.Application creApp
              = app.Application.Create;

            try
            {
                FilteredElementCollector forms = new FilteredElementCollector(doc);
                forms.OfCategory(BuiltInCategory.OST_CurtainGridsWall); // !!problem string!!

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Create Devided Surface");

                    foreach (Form form in forms)
                    {
                        FamilyItemFactory factory = doc.FamilyCreate;
                        Options options = creApp.NewGeometryOptions();
                        options.ComputeReferences = true;
                        options.View = doc.ActiveView;
                        GeometryElement element = form.get_Geometry(options);

                        foreach (GeometryObject geoObject in element) // 2013
                        {
                            Solid solid = geoObject as Solid;
                            foreach (Face face in solid.Faces)
                            {
                                if (face.Reference != null)
                                {
                                    if (null != face)
                                    {

                                    }
                                }
                            }
                        }
                    }
                    tx.Commit();
                }

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }

【问题讨论】:

    标签: c# revit-api


    【解决方案1】:

    如果您需要查找当前文档中的所有墙,只需将 BuiltInCategory.OST_CurtainGridsWall 更改为 BuiltInCategory.OST_Walls,并将元素投射到 Autodesk.Revit.DB.Wall,如下所示:

    UIApplication app = commandData.Application;
    Document doc = app.ActiveUIDocument.Document;
    var walls = new FilteredElementCollector(doc)
        .OfCategory(BuiltInCategory.OST_Walls)
        .WhereElementIsNotElementType()
        .Cast<Autodesk.Revit.DB.Wall>
        .ToList();
    

    如果您需要项目中所有文档的墙 你需要先获取所有链接的文档(链接的文档应该加载到项目中,否则你找不到它们),像这样:

    UIApplication app = commandData.Application;
    var doc = app.ActiveUIDocument.Document;
    List<Autodesk.Revit.DB.Document> linkedDocs = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                    .OfClass(typeof(Autodesk.Revit.DB.RevitLinkInstance))
                    .Cast<Autodesk.Revit.DB.RevitLinkInstance>()
                    .Select(x => x.GetLinkDocument())
                    .ToList();
    

    然后,对于每个文档,重复接收墙。

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2019-03-08
      • 2021-07-15
      • 2019-02-28
      • 2014-03-23
      • 2020-04-20
      相关资源
      最近更新 更多