/////////////////////////////////////////////
//Copyright (c) 2016, SAGA
//All rights reserved.
//文件名称: WallExtend.cs
//文件描述: 墙操作常用扩展方法
//创 建 者: 刘森
//创建日期: 2016-05-03
//版 本 号:1.0.0.0
/////////////////////////////////////////////
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
namespace SAGA.RevitUtils.Extends
{
public static class WallExtend
{
///
/// 墙底部标高
///
///
///
public static Level GetBaseLevel(this Wall wall)
{
ElementId id = wall.GetBaseLevelId();
if (id != ElementId.InvalidElementId && id != null)
{
return wall.Document.GetElement(wall.GetBaseLevelId()) as Level;
}
return null;
}
///
/// 墙面积(㎡)
///
///
public static double GetArea(this Wall wall)
{
return wall.GetParameterDouble(BuiltInParameter.HOST_AREA_COMPUTED).FromApi(DisplayUnitType.DUT_SQUARE_METERS);
}
///
/// 墙底部标高Id
///
///
///
public static ElementId GetBaseLevelId(this Wall wall)
{
return wall.GetParameterElementId(BuiltInParameter.WALL_BASE_CONSTRAINT);
}
///
/// 墙顶部标高
///
///
///
public static Level GetTopLevel(this Wall wall)
{
ElementId id = wall.GetTopLevelId();
if (id != ElementId.InvalidElementId && id != null)
{
return wall.Document.GetElement(wall.GetTopLevelId()) as Level;
}
return null;
}
///
/// 墙顶部标高Id
///
///
///
public static ElementId GetTopLevelId(this Wall wall)
{
return wall.GetParameterElementId(BuiltInParameter.WALL_HEIGHT_TYPE);
}
///
/// 墙底部偏移
///
///
public static double GetBaseOffSet(this Wall wall)
{
return wall.GetParameterDouble(BuiltInParameter.WALL_BASE_OFFSET);
}
///
/// 获取底部高度
///
///
///
public static double GetBaseStaticHeight(this Wall wall)
{
return wall.GetBaseLevel().Elevation + wall.GetBaseOffSet();
}
///
/// 获取顶部高度
///
///
///
public static double GetTopStaticHeight(this Wall wall)
{
return wall.GetTopLevel().Elevation + wall.GetTopOffSet();
}
///
/// 墙顶部偏移
///
///
///
public static double GetTopOffSet(this Wall wall)
{
return wall.GetParameterDouble(BuiltInParameter.WALL_TOP_OFFSET);
}
///
/// 设置墙底部偏移
///
/// 偏移值(英寸)
///
public static void SetBaseOffSet(this Wall wall, double offSet)
{
wall.SetParameter(BuiltInParameter.WALL_BASE_OFFSET, offSet);
}
///
/// 设置墙顶部偏移
///
///
/// 顶部偏移(英寸)
public static void SetTopOffSet(this Wall wall, double offset)
{
wall.SetParameter(BuiltInParameter.WALL_TOP_OFFSET, offset);
}
public static void SetMaterial(this WallType wallTyp, ElementId materialId)
{
CompoundStructure compoundStructure = wallTyp.GetCompoundStructure();
List layerList = compoundStructure.GetLayers().ToList();
int coreIndex = compoundStructure.GetLastCoreLayerIndex();
compoundStructure.SetMaterialId(coreIndex, materialId);
wallTyp.SetCompoundStructure(compoundStructure);
}
}
}