278 lines
9.8 KiB
C#
278 lines
9.8 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Architecture;
|
|
using CDM.Interop.Revit.RevitCompoent;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CDM.Interop.Revit.CDMComponent
|
|
{
|
|
class CDMStairs : CDMComponent
|
|
{
|
|
public CDMStairs(Document doc, View3D view3D, Stairs stairs)
|
|
{
|
|
self = stairs;
|
|
|
|
base.SymbolId = stairs.GetTypeId();
|
|
base.EleId = stairs.Id;
|
|
base.LevelId = stairs.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM).AsElementId();
|
|
//base.Name = stairsType.Name + "@" + stairs.Name;
|
|
base.CDMTypeId = HcdmType.CDMStair;
|
|
|
|
|
|
var stairsType = doc.GetElement(stairs.GetTypeId()) as StairsType;
|
|
|
|
|
|
var stairsLandingType = doc.GetElement(stairsType.LandingType) as StairsLandingType;
|
|
|
|
StairsLanding stairsLanding = doc.GetElement(stairs.GetStairsLandings().FirstOrDefault()) as StairsLanding;
|
|
//var curve = stairsLanding.GetStairsPath();
|
|
var bounding = stairsLanding.get_BoundingBox(view3D);
|
|
XYZ origin = (bounding.Max + bounding.Min) / 2 - new XYZ((bounding.Max.X - bounding.Min.X) / 2, 0, 0);
|
|
Landing = new CDMStairsLanding()
|
|
{
|
|
Xl = origin.X * 304.8 / 1000,
|
|
Yw = origin.Y * 304.8 / 1000,
|
|
Zh = origin.Z * 304.8 / 1000,
|
|
Thickness = stairsLandingType.Thickness * 304.8,
|
|
Width = (bounding.Max.Y - bounding.Min.Y) * 304.8,
|
|
Length = (bounding.Max.X - bounding.Min.X) * 304.8
|
|
};
|
|
|
|
|
|
StairsRunType runType = doc.GetElement(stairsType.RunType) as StairsRunType;
|
|
List<ElementId> StairsRunsIds = stairs.GetStairsRuns().ToList();
|
|
Runs = new List<CDMStairsRun>();
|
|
foreach (ElementId stairsRunId in StairsRunsIds)
|
|
{
|
|
var stairsRun = doc.GetElement(stairsRunId) as StairsRun;
|
|
var l = stairsRun.GetStairsPath().FirstOrDefault() as Line;
|
|
|
|
var radian = l.Direction.AngleTo(new XYZ(1, 0, 0));
|
|
var degrees = radian * 180 / Math.PI;
|
|
if (Math.Round(l.Direction.Y, 2, MidpointRounding.AwayFromZero) < 0)
|
|
{
|
|
degrees += 180;
|
|
}
|
|
CDMStairsRun CDMStairsRun = new CDMStairsRun()
|
|
{
|
|
Xl = l.Origin.X * 304.8 / 1000,
|
|
Yw = l.Origin.Y * 304.8 / 1000,
|
|
Zh = (l.Origin.Z + stairsRun.BaseElevation) * 304.8 / 1000,
|
|
DegreesWithXAxis = degrees,
|
|
Thickness = runType.StructuralDepth * 304.8,
|
|
Width = stairsRun.ActualRunWidth * 304.8,
|
|
Height = stairsRun.Height * 304.8,
|
|
Length = stairsRun.ActualTreadsNumber * stairs.ActualTreadDepth * 304.8,
|
|
NumberOfRisers = stairsRun.ActualRisersNumber
|
|
};
|
|
Runs.Add(CDMStairsRun);
|
|
}
|
|
|
|
//ThicknessOfLanding = Convert.ToDouble(doc.GetElement(stairsType.LandingType).get_Parameter(BuiltInParameter.STAIRS_LANDINGTYPE_THICKNESS).AsValueString());
|
|
|
|
//ThicknessOfLanding = stairsLanding.Thickness;
|
|
//var bounding = stairsLanding.get_BoundingBox(view3D);
|
|
//LengthOfLanding = bounding.Max.X - bounding.Min.X;
|
|
//WidthOfLanding = bounding.Max.Y - bounding.Min.Y;
|
|
//bounding.Max.X
|
|
|
|
// ElevationOfLanding = stairsLanding.BaseElevation;
|
|
|
|
////var stairsRun = doc.GetElement(stair.GetStairsRuns().FirstOrDefault()) as StairsRun;
|
|
//ThicknessOfStairRun = Convert.ToDouble(doc.GetElement(stairsType.RunType).get_Parameter(BuiltInParameter.STAIRS_RUNTYPE_STRUCTURAL_DEPTH).AsValueString());
|
|
|
|
|
|
|
|
|
|
}
|
|
public List<CDMStairsRun> Runs;
|
|
|
|
public CDMStairsLanding Landing;
|
|
/// <summary>
|
|
/// 楼梯信息
|
|
/// </summary>
|
|
/// <param name="document"></param>
|
|
/// <returns></returns>
|
|
private Stairs GetStairInfo(Document document)
|
|
{
|
|
Stairs stairs = null;
|
|
|
|
FilteredElementCollector collector = new FilteredElementCollector(document);
|
|
ICollection<ElementId> stairsIds = collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Stairs).ToElementIds();
|
|
foreach (ElementId stairId in stairsIds)
|
|
{
|
|
if (Stairs.IsByComponent(document, stairId) == true)
|
|
{
|
|
stairs = document.GetElement(stairId) as Stairs;
|
|
|
|
// Format the information
|
|
String info = "\nNumber of stories: " + stairs.NumberOfStories;
|
|
info += "\nHeight of stairs: " + stairs.Height;
|
|
info += "\nNumber of treads: " + stairs.ActualTreadsNumber;
|
|
info += "\nTread depth: " + stairs.ActualTreadDepth;
|
|
|
|
}
|
|
}
|
|
|
|
return stairs;
|
|
}
|
|
/// <summary>
|
|
/// 楼梯类型
|
|
/// </summary>
|
|
/// <param name="stairs"></param>
|
|
private void GetStairsType(Stairs stairs)
|
|
{
|
|
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
|
|
|
|
// Format stairs type info for display
|
|
string info = "Stairs Type: " + stairsType.Name;
|
|
info += "\nLeft Lateral Offset: " + stairsType.LeftLateralOffset;
|
|
info += "\nRight Lateral Offset: " + stairsType.RightLateralOffset;
|
|
info += "\nMax Riser Height: " + stairsType.MaxRiserHeight;
|
|
info += "\nMin Run Width: " + stairsType.MinRunWidth;
|
|
}
|
|
/// <summary>
|
|
/// 添加梯段
|
|
/// </summary>
|
|
/// <param name="stairs"></param>
|
|
private void AddStartandEndRisers(Stairs stairs)
|
|
{
|
|
ICollection<ElementId> runIds = stairs.GetStairsRuns();
|
|
|
|
foreach (ElementId runId in runIds)
|
|
{
|
|
StairsRun run = stairs.Document.GetElement(runId) as StairsRun;
|
|
if (null != run)
|
|
{
|
|
run.BeginsWithRiser = true;
|
|
run.EndsWithRiser = true;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 梯段类型
|
|
/// </summary>
|
|
/// <param name="stairs"></param>
|
|
private void GetRunType(Stairs stairs)
|
|
{
|
|
ICollection<ElementId> runIds = stairs.GetStairsRuns();
|
|
|
|
ElementId firstRunId = runIds.First();
|
|
|
|
StairsRun firstRun = stairs.Document.GetElement(firstRunId) as StairsRun;
|
|
if (null != firstRun)
|
|
{
|
|
StairsRunType runType = stairs.Document.GetElement(firstRun.GetTypeId()) as StairsRunType;
|
|
// Format landing type info for display
|
|
string info = "Stairs Run Type: " + runType.Name;
|
|
info += "\nRiser Thickness: " + runType.RiserThickness;
|
|
info += "\nTread Thickness: " + runType.TreadThickness;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 休息平台
|
|
/// </summary>
|
|
/// <param name="stairs"></param>
|
|
private void GetStairLandings(Stairs stairs)
|
|
{
|
|
ICollection<ElementId> landingIds = stairs.GetStairsLandings();
|
|
string info = "Number of landings: " + landingIds.Count;
|
|
|
|
int landingIndex = 0;
|
|
foreach (ElementId landingId in landingIds)
|
|
{
|
|
landingIndex++;
|
|
StairsLanding landing = stairs.Document.GetElement(landingId) as StairsLanding;
|
|
if (null != landing)
|
|
{
|
|
info += "\nThickness of Landing " + landingIndex + ": " + landing.Thickness;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 楼梯支撑
|
|
/// </summary>
|
|
/// <param name="stairs"></param>
|
|
private void GetStairSupports(Stairs stairs)
|
|
{
|
|
ICollection<ElementId> supportIds = stairs.GetStairsSupports();
|
|
string info = "Number of supports: " + supportIds.Count;
|
|
|
|
int supportIndex = 0;
|
|
foreach (ElementId supportId in supportIds)
|
|
{
|
|
supportIndex++;
|
|
Element support = stairs.Document.GetElement(supportId);
|
|
if (null != support)
|
|
{
|
|
info += "\nName of support " + supportIndex + ": " + support.Name;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Stairs self;
|
|
/// <summary>
|
|
/// 底部标高
|
|
/// </summary>
|
|
public double BaseElevation => self.BaseElevation * 304.8;
|
|
|
|
|
|
}
|
|
class CDMStairsRun : CDMComponent
|
|
{
|
|
/// <summary>
|
|
/// 踢面数
|
|
/// </summary>
|
|
public int NumberOfRisers;
|
|
|
|
/// <summary>
|
|
/// 梯段宽度
|
|
/// </summary>
|
|
public double Width { get; set; }
|
|
|
|
public double Length { get; set; }
|
|
/// <summary>
|
|
/// 楼梯高度
|
|
/// </summary>
|
|
public double Height;
|
|
|
|
/// <summary>
|
|
/// 梯段厚度
|
|
/// </summary>
|
|
public double Thickness { get; set; }
|
|
|
|
}
|
|
class CDMStairsLanding : CDMComponent
|
|
{
|
|
|
|
public CDMStairsLanding()
|
|
{
|
|
|
|
|
|
//Xl;
|
|
//Yw;
|
|
//Zh;
|
|
}
|
|
/// <summary>
|
|
/// 平台板厚度
|
|
/// </summary>
|
|
public double Thickness { get; set; }
|
|
/// <summary>
|
|
/// 平台板长度
|
|
/// </summary>
|
|
public double Length { get; set; }
|
|
/// <summary>
|
|
/// 平台板宽度
|
|
/// </summary>
|
|
public double Width { get; set; }
|
|
/// <summary>
|
|
/// 平台高程
|
|
/// </summary>
|
|
public double Elevation { get; set; }
|
|
|
|
}
|
|
}
|