Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - arti

Pages: [1]
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:
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)

2
Automation Interface, Add-Ins and Tools / Re: Automation using Python?
« on: November 30, 2011, 04:05:29 am »
Quote
Writing EA plug-ins in python also works, but is a different story...

But could you elaborate it for us a little bit? I'd like to write even simple one:)
First of all, according to the EA documentation you have to register the dll with your Add-In using regsrv32 (if compiled as native library) or regasm.exe (if compiled as a .NET DLL). However, when it comes to python we don't have any dll as a result. So do I have to some how make one, for instance using py2exe ? Or maybe there is another way?

Probably (I don't know it for sure) I may have to prepare some Python COM object (example below). Do I have to load Interop.EA.dll library to implement callback functions?  Is it a good way of thinking?

Code: [Select]
# We expose a single method in a Python COM object.
class PythonUtilities:
    _public_methods_ = [ 'SplitString' ]
    _reg_progid_ = "PythonDemos.Utilities"
    # NEVER copy the following ID

    # Use"print pythoncom.CreateGuid()" to make a new one.
    _reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"

    def SplitString(self, val, item=None):
        import string
        if item != None: item = str(item)
        return string.split(str(val), item)

# Add code so that when this script is run by
# Python.exe,.it self-registers.
if__name__=='__main__':
    print "Registering COM server…"
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonUtilities)

Artur

Pages: [1]