[Connect Update 17 C#] How to retrieve the graphic elements visible in a view window?

Hi - I've seen other entries in this forum mention using ScanCriteria to obtain the graphic elements that are visible in a view window. I've experimented successfully with the same using the following code (although the scan I set up does return some elements that are fully outside the view window extent that I've specified to ScanCriteria):

public StatusInt ScanElements(Element element, DgnModelRef mr)
{
  ...
}

Viewport viewPort = Session.GetActiveViewport();
DPoint3d ll, ur;
viewPort.GetViewCorners(out ll, out ur);
DPoint3d[] viewCorners = new DPoint3d[2] { ll, ur };
DPoint3d[] worldCorners = viewPort.ViewToActive(viewCorners);

ScanRange scanRange = new ScanRange();
scanRange.m_xlowlim = (long)(worldCorners[0].X + .5);
scanRange.m_ylowlim = (long)(worldCorners[0].Y + .5);
scanRange.m_xhighlim = (long)(worldCorners[1].X + .5);
scanRange.m_yhighlim = (long)(worldCorners[1].Y + .5);

ScanCriteria scanCriteria = new ScanCriteria();
scanCriteria.SetModelRef(Session.Instance.GetActiveDgnModel());
scanCriteria.SetRangeTest(scanRange);
scanCriteria.SetDrawnElements();
StatusInt si = scanCriteria.Scan(ScanElements);

However, I want to confirm that this is the only/recommended way to do this as opposed to some direct way to achieve this on the viewport by asking the viewport what's currently shown in its view (I studied its methods but nothing jumped out at me).

Thanks,

Martin

Parents Reply Children
No Data