216 lines
7.6 KiB
C#
216 lines
7.6 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Architecture;
|
|
using CDM.Interop.Revit.RevitCompoent;
|
|
using OfficeOpenXml;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CDM.Interop.Revit.RevitCompoent
|
|
{
|
|
class RevitStairs : RevitComponent
|
|
{
|
|
public RevitStairs(string path)
|
|
{
|
|
using (ExcelPackage package = new ExcelPackage(new FileStream(path, FileMode.Open)))
|
|
{
|
|
|
|
ExcelWorksheet sheet = package.Workbook.Worksheets[1];
|
|
//ExcelWorksheet sheet = package.Workbook.Worksheets["基本构件"];
|
|
|
|
this.Name = sheet.Cells["G2"].Value.ToString();
|
|
|
|
this.Comment = sheet.Cells["G4"].Value.ToString();
|
|
|
|
|
|
|
|
Runs = new List<RevitStairsRun>();
|
|
var run1 = new RevitStairsRun()
|
|
{
|
|
Xl = Convert.ToDouble(sheet.Cells["H14"].Value),
|
|
Yw = Convert.ToDouble(sheet.Cells["H15"].Value),
|
|
Zh = Convert.ToDouble(sheet.Cells["H16"].Value),
|
|
DegreesWithXAxis = Convert.ToDouble(sheet.Cells["H17"].Value),
|
|
Length = Convert.ToDouble(sheet.Cells["H18"].Value),
|
|
Width = Convert.ToDouble(sheet.Cells["H19"].Value),
|
|
Height = Convert.ToDouble(sheet.Cells["H20"].Value),
|
|
Thickness = Convert.ToDouble(sheet.Cells["H21"].Value),
|
|
NumberOfRisers = Convert.ToInt32(sheet.Cells["H22"].Value)
|
|
};
|
|
var run2 = new RevitStairsRun()
|
|
{
|
|
Xl = Convert.ToDouble(sheet.Cells["H29"].Value),
|
|
Yw = Convert.ToDouble(sheet.Cells["H30"].Value),
|
|
Zh = Convert.ToDouble(sheet.Cells["H31"].Value),
|
|
DegreesWithXAxis = Convert.ToDouble(sheet.Cells["H32"].Value),
|
|
Length = Convert.ToDouble(sheet.Cells["H33"].Value),
|
|
Width = Convert.ToDouble(sheet.Cells["H34"].Value),
|
|
Height = Convert.ToDouble(sheet.Cells["H35"].Value),
|
|
Thickness = Convert.ToDouble(sheet.Cells["H36"].Value),
|
|
NumberOfRisers = Convert.ToInt32(sheet.Cells["H37"].Value),
|
|
};
|
|
|
|
Runs.Add(run1);
|
|
Runs.Add(run2);
|
|
|
|
ThreadDepth = run1.Length / (run1.NumberOfRisers - 1) / 304.8;
|
|
Landing = new RevitStairsLanding()
|
|
{
|
|
Xl = Convert.ToDouble(sheet.Cells["H23"].Value),
|
|
Yw = Convert.ToDouble(sheet.Cells["H24"].Value),
|
|
Zh = Convert.ToDouble(sheet.Cells["H25"].Value),
|
|
Length = Convert.ToDouble(sheet.Cells["H26"].Value),
|
|
Width = Convert.ToDouble(sheet.Cells["H27"].Value),
|
|
Thickness = Convert.ToDouble(sheet.Cells["H28"].Value),
|
|
};
|
|
|
|
if (run1.Zh < run2.Zh)
|
|
{
|
|
Landing.RelativeElevation = run1.Height;
|
|
run1.RelativeBaseElevation = 0;
|
|
run1.RelativeTopELevation = run1.Height;
|
|
run2.RelativeBaseElevation = Landing.RelativeElevation;
|
|
run2.RelativeTopELevation = Landing.RelativeElevation + run2.Height;
|
|
}
|
|
else
|
|
{
|
|
Landing.RelativeElevation = run2.Height;
|
|
run2.RelativeBaseElevation = 0;
|
|
run2.RelativeTopELevation = run2.Height;
|
|
run1.RelativeBaseElevation = Landing.RelativeElevation;
|
|
run1.RelativeTopELevation = Landing.RelativeElevation + run1.Height;
|
|
}
|
|
TopElevation = getTopElevation(run1, run2);
|
|
BaseElevation = getBaseElevationn(run1, run2);
|
|
}
|
|
}
|
|
public List<RevitStairsRun> Runs;
|
|
public RevitStairsLanding Landing;
|
|
public double TopElevation;
|
|
public double BaseElevation;
|
|
public int GetNumberOfRisers(List<RevitStairsRun> runs)
|
|
{
|
|
int num = 0;
|
|
foreach (var run in runs)
|
|
{
|
|
num += run.NumberOfRisers;
|
|
}
|
|
return num;
|
|
}
|
|
/// <summary>
|
|
/// 顶部偏移
|
|
/// </summary>
|
|
private double getTopElevation(RevitStairsRun run1, RevitStairsRun run2)
|
|
{
|
|
if (run1.Zh > run2.Zh)
|
|
{
|
|
return (run1.Zh * 1000 + run1.Height) / 304.8;
|
|
}
|
|
else
|
|
{
|
|
return (run2.Zh * 1000 + run2.Height) / 304.8;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 底部偏移
|
|
/// </summary>
|
|
private double getBaseElevationn(RevitStairsRun run1, RevitStairsRun run2)
|
|
{
|
|
if (run1.Zh > run2.Zh)
|
|
{
|
|
return run2.Zh * 1000 / 304.8;
|
|
}
|
|
else
|
|
{
|
|
return run1.Zh * 1000 / 304.8;
|
|
}
|
|
}
|
|
public double ThreadDepth { get; private set; }
|
|
}
|
|
class RevitStairsRun : RevitComponent
|
|
{
|
|
/// <summary>
|
|
/// Revit中的定位点
|
|
/// </summary>
|
|
public XYZ rOrigin => new XYZ(Xl, Yw, RelativeBaseElevation / 1000) * 1000 / 304.8;
|
|
|
|
public double Radians => Math.PI / 180 * DegreesWithXAxis;
|
|
public XYZ rDirection => new XYZ(Math.Cos(Radians), Math.Sin(Radians), 0);
|
|
|
|
public XYZ rEndPoint => rOrigin + rDirection * Length / 304.8;
|
|
|
|
/// <summary>
|
|
/// 踢面数
|
|
/// </summary>
|
|
public int NumberOfRisers { get; set; }
|
|
|
|
/// <summary>
|
|
/// 梯段宽度
|
|
/// </summary>
|
|
public double Width { get; set; }
|
|
/// <summary>
|
|
/// 梯段长度
|
|
/// </summary>
|
|
|
|
public double Length { get; set; }
|
|
/// <summary>
|
|
/// 楼梯高度
|
|
/// </summary>
|
|
public double Height { get; set; }
|
|
|
|
/// <summary>
|
|
/// 梯段厚度
|
|
/// </summary>
|
|
public double Thickness { get; set; }
|
|
|
|
public Line LocationLine => Line.CreateBound(rOrigin, rEndPoint);
|
|
|
|
public double RelativeBaseElevation { get; set; }
|
|
|
|
public double RelativeTopELevation { get; set; }
|
|
}
|
|
class RevitStairsLanding : RevitComponent
|
|
{
|
|
|
|
/// <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 RelativeElevation { get; set; }
|
|
|
|
public CurveLoop GetCurves()
|
|
{
|
|
CurveLoop landingLoop = new CurveLoop();
|
|
XYZ p1 = new XYZ(Xl * 1000, Yw * 1000 - Width / 2, 0) / 304.8;
|
|
XYZ p2 = new XYZ(Xl * 1000, Yw * 1000 + Width / 2, 0) / 304.8;
|
|
XYZ p3 = new XYZ(Xl * 1000 + Length, Yw * 1000 + Width / 2, 0) / 304.8;
|
|
XYZ p4 = new XYZ(Xl * 1000 + Length, Yw * 1000 - Width / 2, 0) / 304.8;
|
|
|
|
Line curve_1 = Line.CreateBound(p1, p2);
|
|
Line curve_2 = Line.CreateBound(p2, p3);
|
|
Line curve_3 = Line.CreateBound(p3, p4);
|
|
Line curve_4 = Line.CreateBound(p4, p1);
|
|
|
|
landingLoop.Append(curve_1);
|
|
landingLoop.Append(curve_2);
|
|
landingLoop.Append(curve_3);
|
|
landingLoop.Append(curve_4);
|
|
return landingLoop;
|
|
}
|
|
}
|
|
}
|