我有这段代码可以打开 Inventor 文件对话框。它昨天工作正常,今天不工作。
import win32com.client
def TestFileDialog():
ThisApp = win32com.client.Dispatch("Inventor.Application")
oFileDlg = ThisApp.CreateFileDialog()
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt) #|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Open File Test"
oFileDlg.InitialDirectory = "C:\\Users\\logig\\MoldTools"
oFileDlg.ShowOpen()
TestFileDialog()
在 VS 2017 的交互式窗口上运行代码,我得到以下异常:
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
<ipython-input-1-b46d3a85376d> in <module>()
11 oFileDlg.ShowOpen()
12
---> 13 TestFileDialog()
14
<ipython-input-1-b46d3a85376d> in TestFileDialog()
9 oFileDlg.DialogTitle = "Open File Test"
10 oFileDlg.InitialDirectory = "C:\\Users\\logig\\MoldTools"
---> 11 oFileDlg.ShowOpen()
12
13 TestFileDialog()
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\win32com\client\dynamic.py in ShowOpen(self)
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None)
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
昨天相同的代码运行没有问题。该目录存在,有带有这些扩展名的文件......我完全不知道可能会发生什么变化。将感谢您的帮助。