可以在两个梯段之间添加自动平台或草图平台。静态方法StairsLanding. Canadian AutomaticLanding()将检查两个楼梯梯段是否满足创建自动平台的限制。静态StairsLanding. random AutomaticLanding()方法将返回在两个楼梯梯段之间创建的所有平台的Id。
using (StairsEditScope newStairsScope = new StairsEditScope(document, "New Stairs")) { newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);
using (Transaction stairsTrans = new Transaction(document, "Add Runs and Landings to Stairs")) { stairsTrans.Start();
// Create a sketched run for the stairs IList bdryCurves = new List(); IList riserCurves = new List(); IList pathCurves = new List(); XYZ pnt1 = new XYZ(0, 0, 0); XYZ pnt2 = new XYZ(15, 0, 0); XYZ pnt3 = new XYZ(0, 10, 0); XYZ pnt4 = new XYZ(15, 10, 0);
// Add a straight run Line locationLine = Line.CreateBound(new XYZ(20, -5, newRun1.TopElevation), new XYZ(35, -5, newRun1.TopElevation)); StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center); newRun2.ActualRunWidth = 10;
// Add a landing between the runs CurveLoop landingLoop = new CurveLoop(); XYZ p1 = new XYZ(15, 10, 0); XYZ p2 = new XYZ(20, 10, 0); XYZ p3 = new XYZ(20, -10, 0); XYZ p4 = new XYZ(15, -10, 0); 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);
stairsTrans.Commit(); } // A failure preprocessor is to handle possible failures during the edit mode commitment process. newStairsScope.Commit(new StairsFailurePreprocessor()); }
// create new MultistoryStairs MultistoryStairs multistoryStairs = MultistoryStairs.Create(stairs);
// get all levels that can be connected to this multistoryStairs IEnumerable levelIds = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast().Where(q => multistoryStairs.CanConnectLevel(q.Id)) .Select(q => q.Id);
// Connect the levels to the multistoryStairs // The input to ConnectLevels is a HashSet or SortedSet, so a HashSet is created from the IEnumerable returned by FilteredElementCollector multistoryStairs.ConnectLevels(new HashSet(levelIds));
privatevoidGetRailingType(Stairs stairs) { ICollection<ElementId> railingIds = stairs.GetAssociatedRailings(); foreach (ElementId railingId in railingIds) { Railing railing = stairs.Document.GetElement(railingId) as Railing; RailingType railingType = stairs.Document.GetElement(railing.GetTypeId()) as RailingType;
// Format railing type info for display string info = "Railing Type: " + railingType.Name; info += "\nPrimary Handrail Height: " + railingType.PrimaryHandrailHeight; info += "\nTop Rail Height: " + railingType.TopRailHeight;
private CutMarkType GetCutMark(Stairs stairs) { CutMarkType cutMarkType = null; StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType; Parameter paramCutMark = stairsType.get_Parameter(BuiltInParameter.STAIRSTYPE_CUTMARK_TYPE); if (paramCutMark.StorageType == StorageType.ElementId) // should be an element id { ElementId cutMarkId = paramCutMark.AsElementId(); cutMarkType = stairs.Document.GetElement(cutMarkId) as CutMarkType; }
下面的示例按构件查找所有楼梯,并将有关每个楼梯的一些信息输出到TaskDialog对话框。请注意,此示例使用带有BuiltInCategory.OST_Stairs的类别过滤器,该过滤器将返回所有楼梯的ElementId,因此在从文档中检索时将每个ElementId转换为Stairs类之前,需要进行测试以查看每个ElementId是否代表Stairs By Component。
FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<ElementId> stairsIds = collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Stairs).ToElementIdsElementId(); 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; // Show the information to the user. TaskDialog.Show("Revit", info); } } return stairs; }
privatevoidGetStairsType(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;
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;
TaskDialog.Show("Revit", info); } }
平台
平台由StairsLanding类表示。下面的示例查找Stairs对象的每个平台的厚度。
代码区域:使用楼梯平台
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
privatevoidGetStairLandings(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; } }
楼梯连接 Both StairsRun and StairsLanding have a GetConnections() method which provides information about connections among stairs components (run to run, or run to landing). The method returns a collection of StairsComponentConnection objects which have properties about each connection, including the connection type (to a landing, the start of a stairs run, or the end of a stairs run) and the Id of the connected stairs component. StairsRun和StairsLanding都具有GetConnections()方法,该方法提供有关楼梯构件之间连接的信息(梯段到梯段,或梯段到平台)。该方法返回一个StairsStringentConnection对象的集合,这些对象具有关于每个连接的属性,包括连接类型(连接平台、楼梯梯段起点或楼梯梯段终点)和连接的楼梯构件的ID。
privatevoidGetStairSupports(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; } }