Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: keesbghs on April 22, 2025, 10:41:56 pm

Title: Python win32com is very, very slow
Post by: keesbghs on April 22, 2025, 10:41:56 pm
Hi,
With the Python win32com module it is possible to read the details of Packages, Elements and Realizes. I've used information from
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/repository3.html
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/package_2.html
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/element2.html
I'm getting the data that I want to see.

But it is really, really slow. I have just some 200 elements, which takes almost 6 minutes (!!!) to read.

Did anyone else see this too? What can I do to speed it up?
Title: Re: Python win32com is very, very slow
Post by: Geert Bellekens on April 22, 2025, 11:16:01 pm
The API is very slow whenever you need to loop EA.Collections such as Package.Packages, Package.Elements, Element.Connectors, etc...

The workaround is to use Repository.SQLQuery to get the info you need.
This uses an SQL Query to the database, which is way faster.
In you example it would probably be less then 6 seconds instead of 6 minutes.

Geert
Title: Re: Python win32com is very, very slow
Post by: keesbghs on April 23, 2025, 06:57:56 pm
I had already written some Python code with SQLalchemy, which is indeed much faster. The only problem is that this is basically some sort of reverse engineering. I don't (yet?) want to use that to write into the database.
Title: Re: Python win32com is very, very slow
Post by: Geert Bellekens on April 23, 2025, 08:54:24 pm
I had already written some Python code with SQLalchemy, which is indeed much faster. The only problem is that this is basically some sort of reverse engineering. I don't (yet?) want to use that to write into the database.

I almost never write directly to the database, but whenever I need to query the model I almost always use SQL rather than traversing EA.Collections.
Updating a model is still done over the API. There are methods such as Repository.GetElementByID() that get you the required API object from your query results.

Geert