Visio shape - get X,Y position

2019-05-04 16:12发布

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!

标签: c# visio
1条回答
beautiful°
2楼-- · 2019-05-04 16:20

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)
查看更多
登录 后发表回答