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.
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")