View GetvisibleComponents null

Dear all,

I am trying to find the components that are visible in the view and its random in the results.I have tied few things for ex getting the view via modeldoc2 and also getting the view via DrawingDoc . Both these case are resulting in  null arrays as shown below. What is that i am missing here ?

            DrawingDoc swDrawDoc = null;

            if (modelDoc.GetType() == (int)swDocumentTypes_e.swDocDRAWING)

            {

                swDrawDoc = modelDoc as DrawingDoc;

            }

            SolidWorks.Interop.sldworks.View swView = SWDrawingUtils.GetActivatedView(ref modelDoc, _viewName);

            SolidWorks.Interop.sldworks.View swView3 =  swDrawDoc.GetViewWithName(_viewName);

          

            object[] vDrawChildCompArr = swView.GetVisibleComponents();

            object[] vDrawChildCompArr3 = swView3.GetVisibleComponents();

SolidworksApi macros