2010-09-17 190 views
3

我已經成功地使用下面的代碼編程方式插入的形狀爲Visio:的Visio形狀 - 獲得X,Y位置

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

我將如何編程檢索它的X,形狀已經被插入後Y座標?

謝謝!

回答

4

要獲得新形狀的座標,請首先獲取新形狀的參考。 Page.Drop將重新調用此引用。然後查看該形狀對象的PinXPinY單元。這將爲您提供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)