问题
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