Revit - 将分割表面应用于墙壁
Revit - Apply divided surface to walls
我编写了一个程序,该程序使用对形状面的引用来形成分割面。但是当应用于墙壁时(带有类别选择的搜索字符串在下面突出显示),该程序什么也不做。如何仅将此程序应用于项目中的所有墙壁?
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;
}
}
}
如果你需要找到当前文档中的所有墙,只需将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();
然后,对于每个文档,重复接收墙。
我编写了一个程序,该程序使用对形状面的引用来形成分割面。但是当应用于墙壁时(带有类别选择的搜索字符串在下面突出显示),该程序什么也不做。如何仅将此程序应用于项目中的所有墙壁?
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;
}
}
}
如果你需要找到当前文档中的所有墙,只需将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();
然后,对于每个文档,重复接收墙。