when I read Beam Location, Beam Length, Elevation at Top and Elevation at Bottom from Revit by Revit API, The results are wrong
Example:
on Revit program
Section of Beam = 30 * 60 cm
Beam Length = 4m
Elevation at top = 3 m
Elevation at bottom = 2.4 m
The results from Revit API
Start point = (-46.456047677, 38.915098248, 9.842519685)
End point = (-33.332688097, 38.915098248, 9.842519685)
Beam Length = 13.1233595800525m
Elevation at top = 9.84251968503937 m
Elevation at bottom = 7.87401574803149 m
Why are the results from Revit API wrong?
my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure.StructuralSections;
namespace Plug_In
{
[Transaction(TransactionMode.Manual)]
public class Plug_In : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get Document & UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = commandData.Application.ActiveUIDocument.Document;
// Get All BuiltInParameter
IList<BuiltInParameter> allParameter = Enum.GetValues(typeof(BuiltInParameter)).Cast<BuiltInParameter>().ToList();
String InfoBeam = null;
// Get Beams
ElementCategoryFilter beamFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
IList<Element> allBeams = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).WherePasses(beamFilter).WhereElementIsNotElementType().ToElements();
int BeamCount = allBeams.Count;
// Parameter of Cross Section For Concrete Beam
Parameter beamConcreteHeight = null;
Parameter beamConcreteWidth = null;
foreach (Element ele in allBeams)
{
//Get Element Type
ElementId eleTypeId = ele.GetTypeId();
ElementType eleType = doc.GetElement(eleTypeId) as ElementType;
// Get Height & Width of beam
beamConcreteHeight = eleType.LookupParameter("h");
beamConcreteWidth = eleType.LookupParameter("b");
LocationCurve beamPosition = ele.Location as LocationCurve;
// Get Parameter of Beam
ElementId referenceLevel = null;
ElementId beamMaterial = null;
double startLevelOffset = 0;
double endLevelOffset = 0;
double Length = 0;
double elevationAtTop = 0;
double elevationAtBottom = 0;
Element elementReferenceLevel = null;
Element elementBeamMaterial = null;
foreach (BuiltInParameter bb in allParameter)
{
Parameter p = ele.get_Parameter(bb);
if (p != null)
{
if (p.Definition.Name == "Reference Level")
{
referenceLevel = p.AsElementId();
elementReferenceLevel = doc.GetElement(referenceLevel);
}
if (p.Definition.Name == "Start Level Offset")
{
startLevelOffset = p.AsDouble();
}
if (p.Definition.Name == "End Level Offset")
{
endLevelOffset = p.AsDouble();
}
if (p.Definition.Name == "Length")
{
Length = p.AsDouble();
}
if (p.Definition.Name == "Elevation at Top")
{
elevationAtTop = p.AsDouble();
}
if (p.Definition.Name == "Elevation at Bottom")
{
elevationAtBottom = p.AsDouble();
}
if (p.Definition.Name == "Structural Material")
{
beamMaterial = p.AsElementId();
elementBeamMaterial = doc.GetElement(beamMaterial);
}
}
}
InfoBeam += "Beam Name : " + ele.Name + Environment.NewLine
+ "Beam Category : " + ele.Category.Name + Environment.NewLine
+ "Beam Type Name : " + eleType.Name + Environment.NewLine
+ "Beam Family Name : " + eleType.FamilyName + Environment.NewLine
+ "Beam Id : " + ele.Id + Environment.NewLine
+ "Beam has a curve location." + Environment.NewLine
+ "Start Point : " + beamPosition.Curve.GetEndPoint(0).ToString() + Environment.NewLine
+ "End Point : " + beamPosition.Curve.GetEndPoint(1).ToString() + Environment.NewLine
+ "Beam Height : " + GetParameterValue(beamConcreteHeight) + Environment.NewLine
+ "Beam Width : " + GetParameterValue(beamConcreteWidth) + Environment.NewLine
+ "Beam Level : " + elementReferenceLevel.Name + Environment.NewLine
+ "Start Level Offset : " + startLevelOffset + Environment.NewLine
+ "End Level Offset : " + endLevelOffset + Environment.NewLine
+ "Beam Length : " + Length + Environment.NewLine
+ "Elevation at Top : " + elevationAtTop + Environment.NewLine
+ "Elevation at Bottom : " + elevationAtBottom + Environment.NewLine
+ "Beam Material : " + elementBeamMaterial.Name + Environment.NewLine + Environment.NewLine;
}
// Print The Results
TaskDialog.Show("Information", "Level Count : " + LevelCount + Environment.NewLine + Environment.NewLine
+ "Column Count : " + ColumnCount + Environment.NewLine + Environment.NewLine
+ "Information about Columns : " + Environment.NewLine + InfoColumn + Environment.NewLine
+ "Beam Count : " + BeamCount + Environment.NewLine + Environment.NewLine
+ "Information about Beams : " + Environment.NewLine + InfoBeam + Environment.NewLine
+ "Floor Count : " + FloorCount + Environment.NewLine + Environment.NewLine
+ "Information about Floors : " + Environment.NewLine + InfoFloor + Environment.NewLine);
return Result.Succeeded;
}
public string GetParameterValue(Parameter parameter)
{
switch (parameter.StorageType)
{
case StorageType.Double:
return parameter.AsValueString();
case StorageType.ElementId:
return parameter.AsElementId().IntegerValue.ToString();
case StorageType.Integer:
return parameter.AsValueString();
case StorageType.None:
return parameter.AsValueString();
case StorageType.String:
return parameter.AsString();
default:
return "";
}
}
}
}