From the Centerline.FitPoints.Item(index).Geometry.Parent you can get the drawing view that this fit point locates on.
That does not work for centerlines of type work feature (aka from a work plane) because there are no fit points. Is there any other way, i guess i can test to see if the midpoint is within the view area.
jvj
Hi jvj,
Currently there is not API to tell which drawing view this kind of center line is from. The center line created by including a work plane can be located out of the drawing view area, so I think we need to expose new APIs to tell a center line's parent drawing view.
I realize this is thread is over 5 years old, but has there been any progress on exposing these additional APIs to be able to capture the drawing view from centerlines added by including workfeatures? Thanks!
This isn't a true solution, but it's a close guess.
I found a workaround where you can "guess" which view a centerline belongs to.
It makes a few assumptions:
There are some limitations:
public static class CenterlineExtensions
{
/// <summary>
/// returns true if a center line is horizontal
/// </summary>
/// <param name="centerline"></param>
/// <returns></returns>
public static bool IsHorizontal(this Centerline centerline)
{
const double tolerance = 0.05;
return Math.Abs(centerline.StartPoint.Y - centerline.EndPoint.Y) <= tolerance;
}
/// <summary>
/// returns true if a center line is vertical
/// </summary>
/// <param name="centerline"></param>
/// <returns></returns>
public static bool IsVertical(this Centerline centerline)
{
const double tolerance = 0.05;
return Math.Abs(centerline.StartPoint.X - centerline.EndPoint.X) <= tolerance;
}
/// <summary>
/// Returns the assumed parent view of a centerline. Only works for horizontal and vertical center lines.
/// </summary>
/// <param name="centerline"></param>
/// <returns></returns>
public static DrawingView GuessParentView(this Centerline centerline)
{
const double tolerance = 0.1; //tolerance to
var sheet = centerline.Parent;
foreach (DrawingView view in sheet.DrawingViews)
{
var viewRight = view.Left + view.Width;
var viewBottom = view.Top - view.Height;
var viewCenterX = view.Left + view.Width / 2;
var viewCenterY = view.Top - view.Height / 2;
if (centerline.IsHorizontal() &&
centerline.StartPoint.Y < view.Top + tolerance && // start point is below top
centerline.StartPoint.Y > viewBottom - tolerance && //start point is above bottom
((centerline.StartPoint.X > viewCenterX && centerline.EndPoint.X < viewCenterX) || //start and end points are on opposite sides of view center
(centerline.StartPoint.X < viewCenterX && centerline.EndPoint.X > viewCenterX)) //start and end points are on opposite sides of view center
)
return view;
if (centerline.IsVertical() &&
centerline.StartPoint.X > view.Left - tolerance && //start point is to the right of left edge
centerline.StartPoint.X < viewRight + tolerance && //start point is to the left of right edge
((centerline.StartPoint.Y > viewCenterY && centerline.EndPoint.Y < viewCenterY) || //start and end points are on opposite sides of view center
(centerline.StartPoint.Y < viewCenterY && centerline.StartPoint.Y > viewCenterY)) //start and end points are on opposite sides of view center
)
return view;
}
return null;
}
}