Book a Demo

Author Topic: Unexpected behaviour after loading MDG via API  (Read 3886 times)

Jamo

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Unexpected behaviour after loading MDG via API
« on: September 24, 2020, 07:10:17 pm »
Hello all,

I wrote a python script to load in a new MDG into my project (as part of a bigger automatization script). Now, I have encountered some weird behaviour that I just can't explain.

First of all, if I load in the MDG via 'repository.ImportTechnology(MDG.xml)' instead of the manual 'Import Technology' dialog, the technology can then be expanded/collapsed in the resource browser which let's you inspect the full content of the MDG. That's pretty cool and helpful, but why does this not happen when I manually import the technology?

But the actual problem I'm encountering is the following:
If I install the MDG manually, everything works fine. Toolbox and elements appear and behave correctly. If I install the MDG via API, the Toolbox does not appear in the toolbox browser with its own name but with the Profile's name (e.g. in the toolbox dropdown menu I have to look for 'TheProfile' instead of 'TheToolbox'). Furthermore, the elements do not appear correctly in the toolbox.
In my example, I have 4 different stereotyped elements of type 'Requirement' in my toolbox. Again, if the MDG is manually installed everything works fine. If it's installed via API, I have 4 objects called 'Requirement' in my toolbox with a little open folder as an icon instead of the standard requirement icon. If I drag and drop those elements into a diagram, a dropdown dialog appears that let's me choose between 'Requirement' or 'Requirement'. For both selections, I get the same element stereotype and each of the 4 'Requirement' elements yields one of the stereotypes I have defined.

So, the information is still there and correctly saved, it just gets displayed very weirdly. Funnily enough, the elements are correctly displayed in the resource section of the project.

And lastly: Yesterday, everything worked fine except for EA not 'listening' to the repo.GetProjectInterface().ReloadProject() command. Today, it executes the command correctly, but does not implement the MDG correctly.


I attached my code, in the case I've overlooked a dumb mistake.
Code: [Select]
    if os.path.isfile(filepath):
        print("Importing mdg...")
        with open(filepath, 'r') as MDG:
            # Load xml as ordered dictionary
            MDG_dict = xmltodict.parse(MDG.read())
            #print(json.dumps(MDG_dict, indent=2))  # For inspection
            # Fetch MDG ID and Version for EA interaction
            newMDG_ID = MDG_dict["MDG.Technology"]["Documentation"]["@id"]
            newMDG_Version = MDG_dict["MDG.Technology"]["Documentation"]["@version"]
            # Try to load technology
            if not repo.IsTechnologyLoaded(newMDG_ID):  # is MDG technology loaded into the model?
                # Unparse dict to xml as input for EA
                techIsInstalled = repo.ImportTechnology(xmltodict.unparse(MDG_dict))
                print("Is tech installed: "+str(techIsInstalled))
            else:
                if not repo.GetTechnologyVersion(newMDG_ID) == newMDG_Version:
                    # Unparse dict to xml as input for EA
                    techIsInstalled = repo.ImportTechnology(xmltodict.unparse(MDG_dict))
                    print("Is tech installed: "+str(techIsInstalled))
                else:
                    raise Exception("New MDG is already installed")
        repo.GetProjectInterface().ReloadProject()

    else:
        raise Exception("Bad filepath for new MDG technology")

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Unexpected behaviour after loading MDG via API
« Reply #1 on: September 24, 2020, 07:49:13 pm »
Yeah, ImportTechnology isn't working for me either, I think it's broken.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Unexpected behaviour after loading MDG via API
« Reply #2 on: September 25, 2020, 08:57:13 am »
Did you read the help?

This applies to technologies imported into pre-7.0 versions of Enterprise Architect (imported technologies), not to technologies referenced in version 7.0 and later (referenced technologies).

It predates the way the GUI imports technologies by years. I don't think the function is available in the GUI these days. It can only handle a small subset of the things that can be included in technologies.

PS. In 15.2 the technologies that are imported properly can now be expanded and provide more useful functions than what the old technologies did.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Unexpected behaviour after loading MDG via API
« Reply #3 on: September 25, 2020, 01:31:45 pm »
Did you read the help?

This applies to technologies imported into pre-7.0 versions of Enterprise Architect (imported technologies), not to technologies referenced in version 7.0 and later (referenced technologies).

It predates the way the GUI imports technologies by years. I don't think the function is available in the GUI these days. It can only handle a small subset of the things that can be included in technologies.

PS. In 15.2 the technologies that are imported properly can now be expanded and provide more useful functions than what the old technologies did.
Any idea if here will be an alternative for post-7.0 technologies?

Geert

Jamo

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Unexpected behaviour after loading MDG via API
« Reply #4 on: September 25, 2020, 05:30:10 pm »
Must have had tunnel vision when I read the documentation on the function.

Then I would like to join Geert's question: When will this be available again?
These functions (install/delete MDG by API) are really useful to write a migration script for custom MDGs.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Unexpected behaviour after loading MDG via API
« Reply #5 on: September 25, 2020, 05:44:24 pm »
Jamo,

A possible alternative may be to create an add-in.
From an add-in you can load an MDG (at startup of EA)

Geert

Jamo

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Unexpected behaviour after loading MDG via API
« Reply #6 on: September 25, 2020, 05:53:32 pm »
Thanks, Geert, I will keep that in mind.

So far, I haven't worked with creating add-ins, I only used python scripts. My workaround for the MDG issue is, to open a dialog box that pauses the script until the user has manually exchanged the MDGs. It's not pretty, but it works.