|
Revit 可以创建斜墙,方法是通过先创建一个体量,然后在体量的斜面上创建斜墙。具体步骤请参考帮助。
如果用API来创建斜墙,可用FaceWall.Create() 方法。
那么我们怎样辨别是垂直墙还是斜墙呢? 方法是通过墙的类名称来判断。斜墙用FaceWall类来表达,一般垂直墙用Wall类表达。
一个开发者问到一个问题,如何求出斜墙与水平面的夹角呢?
方法: 用几何数据Geometry方法获得斜墙的几何体,遍历这Solid的六个面,若某一个面的面积乘以墙的厚度等于墙的体积,并且该面的法向向量的Z值为正,那么这个面就是上表面。再构造一个垂直向上的向量(0,0,1),然后用Revit的两个向量的夹角函数获得夹角。
如下图所示:
请看下面的代码演示上面完整过程,显示模型中第一个斜墙与水平面夹角。。
[c-sharp] view plaincopy
//Code for Revit 2011.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class GetSlantedWallAndAngle : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
//Iterate to find the slanted wall.
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_Walls);
FaceWall slantedWall = null;
foreach (Element elem in collector)
{
if (elem is FaceWall) //use the class to identify slanted wall
{
slantedWall = elem as FaceWall;
break;
}
}
if (slantedWall == null)
{
messages = "There is no slanted wall in this model";
return Result.Failed;
}
//get geometry.
Options options = app.Application.Create.NewGeometryOptions();
GeometryElement geoElement = slantedWall.get_Geometry(options);
//get the only one solid
Solid wallSolid = null;
foreach (GeometryObject geoObject in geoElement.Objects)
{
if (geoObject is Solid)
{
wallSolid = geoObject as Solid;
break;
}
}
//get the wall's width
ElementId typeId = slantedWall.GetTypeId();
WallType type = doc.get_Element(typeId) as WallType;
double dWidth = type.Width;
double dTolerance = 0.01;
double dAngle = 0.0;
foreach (PlanarFace face in wallSolid.Faces)
{
if (Math.Abs(face.Area * dWidth - wallSolid.Volume) < dTolerance)
{
if (face.Normal.Z > dTolerance)
{
//calculate the angle.
XYZ verticalVector = new XYZ(0, 0, 1);
dAngle = verticalVector.AngleTo(face.Normal) * 180 / 3.1415926;
TaskDialog.Show("Slant wall angle to XOY plane", dAngle.ToString());
break;
}
}
}
return Result.Succeeded ;
}
}
作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739
|
|