Visio形状 - 获得X,Y位置

Pet*_*ete 4 c# visio

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

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

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

谢谢!

Pat*_*ahy 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")
Run Code Online (Sandbox Code Playgroud)

我注意到你正在使用度量图(即文件名中的_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)
Run Code Online (Sandbox Code Playgroud)