Visio shape - get X,Y position

為{幸葍}努か 提交于 2019-12-07 08:55:06

问题


I've managed to programatically insert a shape into Visio using the code below:

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

How would i programatically retrieve it's X,Y coordinates after the shape has been inserted?

Thanks!


回答1:


To get the coordinates of the new shape first get a reference to the new shape. Page.Drop will retun this reference. Then look in that shape object for its PinX and PinY cells. This will give you the coordinates in Visio's default units i.e. inches. Here is an example in 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")

I notice you are working in a metric drawing (i.e. _M in the filename). You may prefer to work in a different unit. Here is the same example using millimeters:

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)


来源:https://stackoverflow.com/questions/3736712/visio-shape-get-x-y-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!