Hello I have the following code:
public static void HandleStairs(Document doc)
List<TransitionPoint> ret = new List<TransitionPoint>();
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> stairs = collector.OfCategory(BuiltInCategory.OST_Stairs).ToElements();
foreach (var stair in stairs)
{
var st= stair as Stairs;
if(st!=null)
{
%code that is never executed
}
}
return ret;
}
Now the problem is that no matter what it appears stairs are always null, I heard that another programmer had the same problem.
the stairs variable does receive a number of object with stairlike properties (being named staircase, having risers and platforms ext.) but does not actually appear to accept being cast to a stair. Anybody know how to actually cast this into stairs (or otherwise obtain all stairs in an document?)
Note that stairs is an element with the following properties:
Riser to Tread Connection
Monolithic Material
Apply Nosing Profile
Stringer Material
Text Size
Begin with Riser
Stringer Carriage Height
URL
Open Stringer Offset
Right Stringer
Riser Type
Cost
Left Stringer
Underside of Winder
Stringer Height
Nosing Profile
Manufacturer
Middle Stringers
Keynote
Riser Material
Minimum Tread Depth
Text Font
Monolithic Stairs
Maximum Riser Height
Landing Carriage Height
Break Symbol in Plan
Landing Overlap
Extend Below Base
Nosing Length
Assembly Description
End with Riser
Description
Function
Type Image
Type Comments
Stringer Thickness
Assembly Code
Calculation Rules
Trim Stringers at Top
Model
Tread Thickness
Tread Material
Riser Thickness
I mostly need the stair objects to get the runs assosiated with the stair objects, or actually I need the paths the runs follow.
This can hopefully be used to do the following:
var tesselated = new List<XYZ>();
var stairPath = run.GetStairsPath();
foreach (Curve curve in stairPath)
{
tesselated.AddRange(curve.Tessellate());
}
Because I need the XYZ locations for the positions any stairs attached to the geometry of the building.
What you've done looks reasonable, although as others have pointed out, obviously somehow you are getting back an element which is not a Stair element.
I would suggest - in order to make sure you get back what you want, that you use:
.OfClass(typeof(Stairs))
with the FilteredElementCollector. With this, you can probably drop the WhereElementIsNotElementType() and OfCategory() methods, because it is implicit in the above statement.
This way - whatever you get back should be cast-able.