2010-09-17 140 views
3

我已经成功地使用下面的代码编程方式插入的形状为Visio:的Visio形状 - 获得X,Y位置

ActiveWindow.Page.Drop(VisioApp.Documents["ORGCH_M.VSS"].Masters.ItemU["Executive"], 5.433071, 7.559055); 

我将如何编程检索它的X,形状已经被插入后Y坐标?

谢谢!

回答

4

要获得新形状的坐标,请首先获取新形状的参考。 Page.Drop将重新调用此引用。然后查看该形状对象的PinXPinY单元。这将为您提供Visio默认单位(即英寸)中的坐标。这里是一个VBA的例子:

Dim newShape As Visio.Shape 
Dim x As Double 
Dim y As Double 

Set newShape = ActiveWindow.Page.Drop(Visio.Application.Documents("ORGCH_M.VSS") 
        .Masters.ItemU("Executive"), 5.433071, 7.559055) 

x = newShape.Cells("PinX") 
y = newShape.Cells("PinY") 

我注意到你在一个公制图纸(即_M在文件名)工作。你可能更喜欢在不同的单位工作。这里是使用毫米的相同示例:

Dim newShape As Visio.Shape 
Dim xIn As Double 
Dim yIn As Double 
Dim xOut As Double 
Dim yOut As Double 

xIn = Visio.Application.ConvertResult(100, visMillimeters, visInches) 
yIn = Visio.Application.ConvertResult(120, visMillimeters, visInches) 

Set newShape = ActiveWindow.Page.Drop(Visio.Application.Documents("ORGCH_M.VSS") 
        .Masters.ItemU("Executive"), xIn, yIn) 

xOut = newShape.Cells("PinX").Result(visMillimeters) 
yOut = newShape.Cells("PinY").Result(visMillimeters)