How do you Extend a Centre Line in a view ?

Hello every one .

i want to extend my center line upto view outBox for that i wrote one method in c# which is attached below,

firstly i wrote program its work fine as shown in fig 2 and attachment  CentreLine2.

then i have done some simple modification but after that its not work as shown in fig 1 and attachment CentreLine.

can any one please help me.

SolidworksApi macros