I Have try it. Some case it work. Some case it leaves nearest column and rays next column.
View CurView = ui_doc.ActiveView;
IList<Element> elems = KJU.CategoryNameFilterByRectangle(ui_doc , "Structural Framing");
Element elem = doc.GetElement(elems.FirstOrDefault().Id);
List<double> dists = new List<double>();
Curve curve = (elem.Location as LocationCurve).Curve;
if(curve is Line)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
Func<View3D , bool> isNotTemplate = v3 => !(v3.IsTemplate);
View3D view3D = collector.OfClass(typeof(View3D)).Cast<View3D>().First<View3D>(isNotTemplate);
ElementId bm_symID;
bm_symID = elem.GetTypeId();
Element Symele = doc.GetElement(bm_symID);
string Z_just = elem.get_Parameter(BuiltInParameter.Z_JUSTIFICATION).AsValueString();
double Z_just_ofs = elem.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).AsDouble(),
Bm_depth = Symele.GetParameters("Beam Depth")[0].AsDouble(),
Bm_Top_Level = 0, bm_center_lvl = 0,
Bm_Z_locationLevel = curve.GetEndPoint(0).Z;
if(Z_just.Equals("Top"))
{
Bm_Top_Level = Bm_Z_locationLevel + Z_just_ofs;
}
else if(Z_just.Equals("Bottom"))
{
Bm_Top_Level = Bm_Z_locationLevel + Z_just_ofs + Bm_depth;
}
else if(Z_just.Equals("Center"))
{
Bm_Top_Level = Bm_Z_locationLevel + Z_just_ofs + Bm_depth * 0.5;
}
else
{
Bm_Top_Level = Bm_Z_locationLevel + Z_just_ofs;
}
bm_center_lvl = Bm_Top_Level - 0.5 * Bm_depth;
XYZ cur_mid_point = curve.Evaluate(0.5 , true),
Bm_center_point = new XYZ(cur_mid_point.X , cur_mid_point.Y , bm_center_lvl);
//DrawCircle(ui_doc , Bm_center_point , 0.25 , new XYZ(0 , 0 , 1));
XYZ dir_st2end = curve.GetEndPoint(1) - curve.GetEndPoint(0),
dir_end2st = curve.GetEndPoint(0) - curve.GetEndPoint(1);
// Filtering StructuralColumns
ElementClassFilter filter1 = new ElementClassFilter(typeof(FamilyInstance));
ElementCategoryFilter filter2 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);
LogicalAndFilter filter = new LogicalAndFilter(filter1 , filter2);
ReferenceIntersector refIntersector = new ReferenceIntersector(filter , FindReferenceTarget.Face , view3D);
IList<ReferenceWithContext> referenceWithContext1 = refIntersector.Find(Bm_center_point , dir_st2end);
XYZ refp2 = referenceWithContext1[1].GetReference().GlobalPoint,
refp1 = referenceWithContext1[0].GetReference().GlobalPoint;
Double Bearing_End = refp1.DistanceTo(refp2);
IList<ReferenceWithContext> referenceWithContext2 = refIntersector.Find(Bm_center_point , dir_end2st);
Double Bearing_start = referenceWithContext2[0].GetReference().GlobalPoint.DistanceTo(referenceWithContext2[1].GetReference().GlobalPoint);
TaskDialog.Show("Angle of Curve , Start Bearing, End Bearing" ,
"Frame Rotation angle in degree = " + KJU.GetAngleinDegree(curve.GetEndPoint(0) , curve.GetEndPoint(1)) +
"\n Column Support Bearing @ Start Point = " + KJU.Feet2FeetandInches(Bearing_start) +
"\n Column Support Bearing @ End Point = " + KJU.Feet2FeetandInches(Bearing_End));
dists.Add(Bearing_start); dists.Add(Bearing_End);
}
if(curve is Arc)
{
}