Product : Engine, Version : 5.1.1.1038, ArticleID : 41024070

HowTo : How to create a viewport from an object

Article41024070
TypeHowTo
ProductEngine
Version5.1.1.1038
Date Added8/4/2005
Submitted byFell-Kernbach
Keywords

Subject

How to create a viewport from an object

Summary

   See attached a vdf-file with an polygonal viewport. When you try to zoom to extents nothing happens, trying to pan does not work.
Using a rectangle viewport works very well.

Solution

   The viewport was created wrong center height and width parameters.
The code below solves the problem:

      VDPro1.ActiveDocument.Open "c:\downloads\e2.vdf"
      Dim poly As vdPolyline
      Dim vp As vdViewport
      Dim boundary As Variant
      Set poly = VDPro1.ActiveDocument.GetFromHandle("4ED")
      Set vp = VDPro1.ActiveDocument.GetFromHandle("4F6")
      boundary = poly.GetBoundingBox
      vp.Center = Array((boundary(0) + boundary(2)) / 2#, (boundary(1) + boundary(3)) / 2#)
      vp.Width = boundary(2) - boundary(0)
      vp.Height = boundary(3) - boundary(1)
      vp.Invalidate

To correctly create a viewport from an object (polyline circle etc) you can see the vdViewport example in our help, especially the lines:

      Set circ = lay1.Entities.AddCircle(Array(0, 30), 14)
      boundary = circ.GetBoundingBox
      Set vport = lay1.Entities.AddViewPort(Array((boundary(0) + boundary(2)) / 2#, _
            (boundary(1) + boundary(3)) / 2#), _
            boundary(2) - boundary(0), _
            boundary(3) - boundary(1))
      vport.ClipObjHandle = circ.Handle
      vport.ViewCenter = Array(-15, 0, 0)
      vport.TargetPoint = Array(30, 15, 7.5)
      vport.ViewSize = 40