Visio形状 - 获得X,Y位置

时间:2010-09-17 15:30:31

标签: c# visio

我已设法使用以下代码以编程方式将形状插入Visio:

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

如何在插入形状后以编程方式检索它的X,Y坐标?

谢谢!

1 个答案:

答案 0 :(得分:5)

要获取新形状的坐标,首先要获得对新形状的引用。 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)