Revit API获取几何信息 - 墙的底面面积
通过element.get_Geometry(opt);可以获取对象的几何信息。
参数Option指定参数的限制条件,比如详细程度,哪个视图。
获得的几何信息保存在一个数组中,可以通过遍历得到点,面等信息。
from:http://revit.5d6d.com/thread-1285-1-1.html
参数Option指定参数的限制条件,比如详细程度,哪个视图。
获得的几何信息保存在一个数组中,可以通过遍历得到点,面等信息。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetWallBFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a wall
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a wall");
Element elem = doc.GetElement(ref1);
Wall wall = elem as Wall;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
FindBottomFace(solid);
}
return Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("Wall Bottom Face", "Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + " " + pf.Origin.Y.ToString() + " " + pf.Origin.Z.ToString() + ")");
break;
}
}
}
return pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetColumnBottomFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a column
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a column");
Element elem = doc.GetElement(ref1);
FamilyInstance column = elem as FamilyInstance;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = column.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
if (obj is Solid)
{
Solid solid = obj as Solid;
FindBottomFace(solid);
}
else if (obj is GeometryInstance)
{
GeometryInstance geoInstance = obj as GeometryInstance;
GeometryElement geoElement = geoInstance.GetInstanceGeometry();
foreach (GeometryObject obj2 in geoElement.Objects)
{
if (obj2 is Solid)
{
Solid solid2 = obj2 as Solid;
if (solid2.Faces.Size > 0)
FindBottomFace(solid2);
}
}
}
}
return Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("column Bottom Face", "Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + " " + pf.Origin.Y.ToString() + " " + pf.Origin.Z.ToString() + ")");
break;
}
}
}
return pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetWallBottomFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a wall
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Pick a wall");
Element elem = doc.GetElement(ref1);
Wall wall = elem as Wall;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
{
FindBottomFaces(solid);
}
}
return Result.Succeeded;
}
Face FindBottomFaces(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("the bottom face's area is ", pf.Area.ToString());
}
}
}
return pf;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetWallBFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a wall
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a wall");
Element elem = doc.GetElement(ref1);
Wall wall = elem as Wall;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
FindBottomFace(solid);
}
return Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("Wall Bottom Face", "Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + " " + pf.Origin.Y.ToString() + " " + pf.Origin.Z.ToString() + ")");
break;
}
}
}
return pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetColumnBottomFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a column
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a column");
Element elem = doc.GetElement(ref1);
FamilyInstance column = elem as FamilyInstance;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = column.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
if (obj is Solid)
{
Solid solid = obj as Solid;
FindBottomFace(solid);
}
else if (obj is GeometryInstance)
{
GeometryInstance geoInstance = obj as GeometryInstance;
GeometryElement geoElement = geoInstance.GetInstanceGeometry();
foreach (GeometryObject obj2 in geoElement.Objects)
{
if (obj2 is Solid)
{
Solid solid2 = obj2 as Solid;
if (solid2.Faces.Size > 0)
FindBottomFace(solid2);
}
}
}
}
return Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("column Bottom Face", "Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + " " + pf.Origin.Y.ToString() + " " + pf.Origin.Z.ToString() + ")");
break;
}
}
}
return pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetWallBottomFace : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//select a wall
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Pick a wall");
Element elem = doc.GetElement(ref1);
Wall wall = elem as Wall;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
foreach (GeometryObject obj in e.Objects)
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
{
FindBottomFaces(solid);
}
}
return Result.Succeeded;
}
Face FindBottomFaces(Solid solid)
{
PlanarFace pf = null;
foreach (Face face in solid.Faces)
{
pf = face as PlanarFace;
if (null != pf)
{
if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
{
TaskDialog.Show("the bottom face's area is ", pf.Area.ToString());
}
}
}
return pf;
}
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。