Centerline and View

Centerline and View

wannensn
Enthusiast Enthusiast
827 Views
6 Replies
Message 1 of 7

Centerline and View

wannensn
Enthusiast
Enthusiast

Hello,

how can I find out to which DrawingView a centerline belongs?

 

Thanks, Stephan

0 Likes
828 Views
6 Replies
Replies (6)
Message 2 of 7

YuhanZhang
Autodesk
Autodesk

From the Centerline.FitPoints.Item(index).Geometry.Parent you can get the drawing view that this fit point locates on.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 7

wannensn
Enthusiast
Enthusiast

Hi,

 

thanks that works.

 

But I've got another problem;-) How to get the view of a centermark.

 

Regards, Stephan

0 Likes
Message 4 of 7

Anonymous
Not applicable

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

0 Likes
Message 5 of 7

YuhanZhang
Autodesk
Autodesk

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.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 6 of 7

GregNiksch
Contributor
Contributor

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!

0 Likes
Message 7 of 7

el_jefe_de_steak
Collaborator
Collaborator

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: 

  1. The projected plane's lateral position is within the boundaries of the view
    • This gets us close to the correct view
  2. The end points of the projected plane line are on opposite sides of the view center
    • This eliminates picking the view "beside" the correct one

 

There are some limitations:

  1. If the projected work plane is "outside" the boundaries of it's parent view, the function returns null (nothing)
  2. If the projected work plane doesn't cross the center of the view, in the longitudinal direction
    • This should only be a problem if your views get a lot larger than they were when the work plane was added

 

 

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;
    }
}