前言
Ramp 没有直接的 Revit API 可以用。不过最近研究了一下 IFC,发现倒是有另外一个途径。不过,你想把这些内容从 Autodesk 的开源项目中分离出来,估计需要花点功夫。https://github.com/Autodesk/revit-ifc
坡道 Revit API
命名空间:Autodesk.Revit.DB.IFC
类名:ExporterIFCUtils
IFCLegacyStairOrRamp legacyStairOrRamp = ExporterIFCUtils.GetLegacyStairOrRampComponents(exporterIFC, legacyStair);
找到坡道的 Walk Line
Revit API:IFCLegacyStairOrRamp::GetWalkLines
代码出处:这里
/// <summary>
/// Creates walk line representations from stair walk lines.
/// </summary>
/// <param name="exporterIFC">The exporter.</param>
/// <param name="legacyStair">The stair.</param>
/// <param name="legacyStairElem">The stair element.</param>
/// <returns>The walk line representation handles. Some of them may be null.</returns>
static IList<IFCAnyHandle> CreateWalkLineReps(ExporterIFC exporterIFC, IFCLegacyStairOrRamp legacyStair, Element legacyStairElem)
{
IList<IFCAnyHandle> walkLineReps = new List<IFCAnyHandle>();
IFCAnyHandle contextOfItemsWalkLine = exporterIFC.Get3DContextHandle("Axis");
ElementId cateId = CategoryUtil.GetSafeCategoryId(legacyStairElem);
Transform lcs = Transform.Identity;
XYZ projDir = XYZ.BasisZ;
IList<IList<Curve>> curvesArr = legacyStair.GetWalkLines();
foreach (IList<Curve> curves in curvesArr)
{
IFCAnyHandle curve = GeometryUtil.CreateIFCCurveFromCurves(exporterIFC, curves, lcs, projDir);
if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curve))
{
HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
bodyItems.Add(curve);
walkLineReps.Add(RepresentationUtil.CreateShapeRepresentation(exporterIFC, legacyStairElem, cateId,
contextOfItemsWalkLine, "Axis", "Curve2D", bodyItems));
}
else
walkLineReps.Add(null);
}
return walkLineReps;
}
找到坡道的边界线
Revit API:IFCLegacyStairOrRamp::GetBoundaryLines
代码出处:这里
/// <summary>
/// Creates boundary line representations from stair boundary lines.
/// </summary>
/// <param name="exporterIFC">The exporter.</param>
/// <param name="legacyStair">The stair.</param>
/// <param name="legacyStairElem">The stair element.</param>
/// <returns>Boundary line representations.</returns>
static IList<IFCAnyHandle> CreateBoundaryLineReps(ExporterIFC exporterIFC, IFCLegacyStairOrRamp legacyStair, Element legacyStairElem)
{
IFCAnyHandle contextOfItemsBoundary = exporterIFC.Get3DContextHandle("FootPrint");
IList<IFCAnyHandle> boundaryLineReps = new List<IFCAnyHandle>();
IFCFile file = exporterIFC.GetFile();
ElementId cateId = CategoryUtil.GetSafeCategoryId(legacyStairElem);
HashSet<IFCAnyHandle> curveSet = new HashSet<IFCAnyHandle>();
IList<CurveLoop> boundaryLines = legacyStair.GetBoundaryLines();
foreach (CurveLoop curveLoop in boundaryLines)
{
Transform lcs = Transform.Identity;
foreach (Curve curve in curveLoop)
{
if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
{
IFCAnyHandle curveHnd = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, curve);
//IList<int> segmentIndex = null;
//IList<IList<double>> pointList = GeometryUtil.PointListFromCurve(exporterIFC, curve, null, null, out segmentIndex);
For now because of no support in creating IfcLineIndex and IfcArcIndex yet, it is set to null
IList<IList<int>> segmentIndexList = new List<IList<int>>();
segmentIndexList.Add(segmentIndex);
//IList<IList<int>> segmentIndexList = null;
//IFCAnyHandle pointListHnd = IFCInstanceExporter.CreateCartesianPointList3D(file, pointList);
//IFCAnyHandle curveHnd = IFCInstanceExporter.CreateIndexedPolyCurve(file, pointListHnd, segmentIndexList, false);
if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveHnd))
curveSet.Add(curveHnd);
}
else
{
IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, lcs, XYZ.BasisZ, false);
ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, XYZ.Zero, false);
IList<IFCAnyHandle> curves = info.GetCurves();
if (curves.Count == 1 && !IFCAnyHandleUtil.IsNullOrHasNoValue(curves[0]))
{
curveSet.Add(curves[0]);
}
}
}
IFCAnyHandle curveRepresentationItem = IFCInstanceExporter.CreateGeometricSet(file, curveSet);
HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
bodyItems.Add(curveRepresentationItem);
IFCAnyHandle boundaryLineRep = RepresentationUtil.CreateGeometricSetRep(exporterIFC, legacyStairElem, cateId, "FootPrint",
contextOfItemsBoundary, bodyItems);
boundaryLineReps.Add(boundaryLineRep);
}
return boundaryLineReps;
}
总结
IFC 作为一个行业标准,各个厂商都会有自己的实现,并且这些实现对基本的元素都要支持。从这个思路出发,可以发现一些隐藏的功能。