【发布时间】:2019-01-01 07:24:14
【问题描述】:
我正在尝试在后台为用户自动化 ChemDraw,最好避免使用 SendKeys(),因为我认为这需要一个 ChemDraw 实例才能工作。我需要做的是以某种方式以编程方式单击编辑 -> 复制为 -> InChI,然后从 Windows 剪贴板中检索结果。
我们目前正在使用 Python 和 COM 脚本来尝试此操作。这是我们当前的代码:
# Opens ChemDraw and loads the file, while keeping the window hidden.
ChemDraw = w32.DispatchEx('ChemDraw.Application') # ChemDraw Application Object
ChemDraw.Visible = False # Makes Invisible
Compound= ChemDraw.Documents.Open(cdx_filepath) # ChemDraw File Object (Can be seen with ChemDraw.Activate())
# Selects the whole molecule.
Compound.Objects.Select()
# Here is where we need to figure out how to do CopyAs and Save off clipboard content.
# Saves the file and Quits afterwards.
Compound.SaveAs(jpg_filepath)
ChemDraw.Quit()
我想我有两个问题:我们如何访问工具栏中的“编辑”以及其中的结果值?如何获取由“ChemDraw = w32.DispatchEx('ChemDraw.Application')”之类的行生成的对象并确定可以用它做什么?部分问题是我们似乎无法自省生成的 DispatchEx 对象,因此我们很难回答自己的问题。
【问题讨论】:
标签: python automation com win32com