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.
First of all, you absolutely have to find out and tell us what kind of element you are talking about. Otherwise, this discussion is completely pointless. One very easy way to determine that is to explore the 'stair-like' element using RevitLookup:
https://github.com/jeremytammik/RevitLookup
If you do not know what RevitLookup is, you should stop absolutely everything else you are doing with the Revit API right away and start off fresh by working through the Revit API getting started material, especially installing and starting to use RevitLookup:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
The filtered element collector you show retrieves all elements of the 'Stairs' category. This 'stair-like object' could be a DirectShape, in which case you can assign it the 'Stairs' category. Then it will be retrieved by your filtered element collector above.
Here is an example of a 'stair-like' extruded roof, which is and will always remain a roof, with the 'Roofs' category, and thus can never be identified by your filtered element collector:
http://thebuildingcoder.typepad.com/blog/2014/09/events-again-and-creating-an-extrusion-roof.html#7
Sorry for the confusing answer, but I must say your question is pretty confusing too. Never heard anything like it before. I hope this helps.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With