0

I have an application (Solidworks in my case, link is to the com_obj documentation for reference) that has an api. I can access and use the the object by:

import pythoncom
import win32com.client
from win32com.client import VARIANT

com_obj = win32com.client.Dispatch("SLDWORKS.Application")

arg = win32com.client.VARIANT(pythoncom.VT_I4, 1)
com_obj.SomeMethod(arg)

The problem is, how to know what methods are in com_obj as there is no code completion when you type com_obj. . Obviously the documentation for the api is the answer, but is there a way to do this?

Garret45
  • 11
  • 2
  • Try using `com_obj = win32com.client.gencache.EnsureDispatch("SLDWORKS.Application")` instead. This generates a Python wrapper for the object. This may, or may not help with code completion, but you can access the generated python files which will have all the methods/properties of the interface with their parameters. As an aside, you usually don't have to do explicit conversion of the parameters to VARIANT: `win32com` will take care of that for you if it can (eg in your code, just pass `1` to `SomeMethod`). – DS_London Aug 01 '22 at 06:53
  • Thanks for this I have tried to use this but get an error (something along the lines of 'you need to do manually with makepy). So I have run the makepy function form the pywin32com.client and chose the relevant DLL (there are around 15 related to the Solid works app), this makes a .py file where the name is the object ID. In this it has all the methods I want to use. Do you know how to use this now? I have tried importing and passing in the com obj as the argument to the method that I think is correct (in my case the class that has the method $SomeMethod, but I get an error. Any suggestions? – Garret45 Aug 09 '22 at 14:51
  • Once you have generated the files you should be able to go back and simply use `win32com.client.Dispatch()` to create the object. – DS_London Aug 10 '22 at 05:00

0 Answers0