Search code examples
pythonenterprise-architectwin32comcomobject

How to get the Object_Id from COM Object in Enterprise Architect


I tried to find a string in the content of the element of Enterprise Architect using python. I read the excel column by column and search the string in the EAP using SQL query.

Code

App = win32com.client.Dispatch(EAId)
for row in range(2,sheet.max_row):
  firstline = sheet['E' + str(row)].value.strip().splitlines()[0]
  reqCollection = App.Repository.GetElementSet("select Object_ID " + " from t_object where t_object.Note like '" + firstline + "*' and t_object.name like 'SRC*'", 2)

if len(reqCollection) > 0:
  print(reqCollection[0])
  #print(reqCollection[0].Object_ID) Error
  #print(reqCollection[0].Name)  Error

I am able to get the elements from the Query but the problem is I am not able to get the Object_Id or name of the Object. The above code is giving <COMObject <unknown>> as a result. How can I get the Object ID from the COMObject?


Solution

  • I don't think you can index an EA.Collection like that.

    As always it helps to read the documentation:

    You can get an item from the collection using the operation GetAt(index), or you can do a foreach to iterate the elements in the collection.

    Also EA.Element does not have a property called Object_ID, that is the name of the column in the database. The object ID can be retrieved from the property ElementID