1
Automation Interface, Add-Ins and Tools / Re: Automation using Python?
« on: December 20, 2011, 08:57:25 am »
I've finally got it.
I know how to write EA plug-ins in python. As a matter of fact this is pretty close to that what was written in last post. As a prerequisite you should have Python and pywin32 (Python Extensions for Windows) installed for the python version you use. Personally I used version 3.1
Below there is a sample snippet ... but to use it you have to register the COM Server It can be done by executing command python ShowMeDoDemo.py. The vital issue here is that you can choose to respond to any Add-In event. Using the attribute named _public_methods_ you can set a list of strings that contains the names of the public methods for the object. In our case we have 'EA_FileOpen', 'EA_GetMenuItems' and 'EA_MenuClick'. The attribute _reg_progid_ is the progID for the object. This is the name of the COM object clients use to create the object and in order to EA see it you have to add it as a new key value under the location: HKEY_CURRENT_USER\Software\Sparx Systems\EAAddIns
example:
and the snippet

Below there is a sample snippet ... but to use it you have to register the COM Server It can be done by executing command python ShowMeDoDemo.py. The vital issue here is that you can choose to respond to any Add-In event. Using the attribute named _public_methods_ you can set a list of strings that contains the names of the public methods for the object. In our case we have 'EA_FileOpen', 'EA_GetMenuItems' and 'EA_MenuClick'. The attribute _reg_progid_ is the progID for the object. This is the name of the COM object clients use to create the object and in order to EA see it you have to add it as a new key value under the location: HKEY_CURRENT_USER\Software\Sparx Systems\EAAddIns
example:
Code: [Select]
[HKEY_CURRENT_USER\Software\Sparx Systems\EAAddIns\ShowMeDo]
@="ShowMeDo.Demo"
and the snippet
Code: [Select]
import win32com.client
class ShowMeDoDemo:
_public_methods_ = [ 'EA_FileOpen', 'EA_GetMenuItems', 'EA_MenuClick' ]
_reg_progid_ = "ShowMeDo.Demo"
# use
# import pythoncom
# print pythoncom.CreateGuid()
# to make a GUID as they are machine-specific
_reg_clsid_ = "{45B99DFF-462D-4995-83B3-8532D7739BE0}"
def EA_FileOpen(self, repo_obj):
"Callback EA_FileOpen"
repo = win32com.client.Dispatch(repo_obj)
print ("ConnectionString = ", repo.ConnectionString)
def EA_GetMenuItems(self, repo_obj, menuLocation, menuName):
"Callback EA_GetMenuItems"
if menuName == "":
return "-DoDemo"
else:
return "Show Dialog"
def EA_MenuClick(self, repo_obj, menuLocation, menuName, itemName):
"Callback EA_MenuClick"
repo = win32com.client.Dispatch(repo_obj)
...
if __name__ == "__main__":
# use 'python ShowMeDoDemo.py' to register the COM server
# use 'python ShowMeDoDemo.py --unregister' to unregister it
print ("Registering COM server...")
import win32com.server.register
win32com.server.register.UseCommandLine(ShowMeDoDemo)