I'm trying to automate ChemDraw for a user in the background, preferably avoiding using SendKeys() as I believe that requires a ChemDraw instance to be visible for that to work. What I need to do is somehow click Edit -> Copy As -> InChI programmatically, then retrieve the result from the Windows clipboard.
We're currently using Python and COM scripting to attempt this. Here's our current code:
# 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()
I guess I have two questions: how do we access "Edit" in the toolbar and the resulting values in it? How do take the resulting object made from a line like "ChemDraw = w32.DispatchEx('ChemDraw.Application')" and determine what you can do with it? Part of the issue is that we can't seem to introspect the resulting DispatchEx object, thus we're having a hard answering our own question.