【发布时间】:2010-09-20 23:38:09
【问题描述】:
我已设法使用以下代码以编程方式将形状插入 Visio:
ActiveWindow.Page.Drop(VisioApp.Documents["ORGCH_M.VSS"].Masters.ItemU["Executive"], 5.433071, 7.559055);
插入形状后如何以编程方式检索它的 X、Y 坐标?
谢谢!
【问题讨论】:
我已设法使用以下代码以编程方式将形状插入 Visio:
ActiveWindow.Page.Drop(VisioApp.Documents["ORGCH_M.VSS"].Masters.ItemU["Executive"], 5.433071, 7.559055);
插入形状后如何以编程方式检索它的 X、Y 坐标?
谢谢!
【问题讨论】:
要获得新形状的坐标,首先要获得对新形状的引用。 Page.Drop 将重新调整此引用。然后在该形状对象中查找其PinX 和PinY 单元格。这将为您提供 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)
【讨论】: