我正在尝试使用python和win32com自动化Microstation,但是在尝试重新发送通过COM接口创建的对象时遇到以下错误。有人能帮我排除故障吗?在
import win32com.client
MS = win32com.client.Dispatch("MicroStationDGN.Application")
MS.Visible = 1
DF = MS.OpenDesignFile("C:\\mydgn.dgn", False)
print(DF.Models.Count)
startPoint = MS.Point3dFromXYZ(2.0,2.0,0.0)
endPoint = MS.Point3dFromXYZ(4.0,4.0,0.0)
line = MS.CreateLineElement2(None, startPoint, endPoint)
print(line)
MS.ActiveModelReference.AddElement(line)
line.redraw()
在AddElement
行中,我得到了以下错误:
但是打印给了我一个有效的com对象。。。在
(<win32com.gen_py.Bentley MicroStation DGN 8.9 Object
Library._LineElement instance at 0x119452224>, com_struct(X=2.0,
Y=2.0, Z=0.0), com_struct(X=4.0, Y=4.0, Z=0.0))
假设Microstation DGN Library作为参考模块加载,ExcelVBA中的等效项如下所示。在
Sub MSFromXlReference()
Dim MS As MicroStationDGN.Application
Dim DesignFile As DesignFile
Dim Line As LineElement
Dim startPoint As Point3d
Dim endPoint As Point3d
Set MS = New MicroStationDGN.Application
MS.Visible = 1
Set DesignFile =
MS.OpenDesignFile("C:\\mydgn.dgn", False)
startPoint = MS.Point3dFromXYZ(2#, 2#, 0#)
endPoint = MS.Point3dFromXYZ(4#, 4#, 0#)
Set Line = MS.CreateLineElement2(Nothing, startPoint, endPoint)
MS.ActiveModelReference.AddElement Line
Line.redraw
End Sub
目前没有回答
相关问题 更多 >
编程相关推荐