Follow us on Twitter
Follow us in Facebook
Office Dev Content
SharePoint Dev Content
[Revised, thanks to suggestions from Eric Schmidt!]
Certain methods in the Visio VBA object model take parameters that specify screen positions, typically for dropping new shapes or positioning existing ones. For example, the Page.DrawLine method takes four Double parameters-xBegin, yBegin, xEnd, and yEnd-that specify the x-axis and y–axis page coordinates of the beginning and end of the line you want to draw on the page. That’s all pretty straightforward. If your drawing uses US units (inches), the values you pass for these parameters will correspond exactly to the page coordinates where the beginning and end of the resulting line appear on your drawing page.
So, let’s say you pass the method the following values: 3, 3, 8, 8, and that your drawing uses US units (inches). Remember that the coordinate origin (0,0) of the page in Visio is in the lower left-hand corner. Here’s what the result should look like:
But now let’s say you want to draw a line in the same relative position on the page in a drawing that uses metric units (millimeters). Consider this page (note the metric units on the rulers):
You might expect to have to pass the method coordinates something like 50, 200, 100, 260. (Those numbers are not intended to be exact metric equivalents of the US units, but merely to represent points in the same general area of the page.) Try it and see what happens. Apparently, nothing happens! Your drawing will look exactly like the lower figure above—that is, an empty page. That’s unless you scroll around off the surface of the drawing page until, perhaps, you stumble upon the line you drew.
The explanation is that despite the fact that your drawing is in metric units, Visio expects you to pass US units (inches) for the parameters of the DrawLine method. So, in fact, you told Visio to draw a line from the point 50, 200 to the point 100, 260—all in inches! No wonder it’s off the drawing page!
DrawLine is just one of many methods that work this way. Others include the following:
Some methods of the Curve and Master objects also fall into this category.
There is a Visio enumeration, VisMeasurementSystem, that contains constants that allow you to specify the measurement specify. But that enumeration is typically used only for methods whose purpose is to open a stencil; for example, the Documents.AddEx method. To the best of my knowledge, it isn’t used for methods like the position-related ones listed above. If you know of an example to the contrary, please let me know.