我已经设法使用以下代码以编程方式将形状插入到 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)
关于c# - Visio 形状 - 获取 X、Y 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3736712/