Hello
I am writing a small add-in to allow us to load multiple XMI files in an Enterprise Architect project. So far it works in certain cases and does everything it is supposed to do, but there appears to be certain states in which the command ImportPackageXMI does not work as intended. One of these reproductible states is upon creating a brand new EAP file and attempting to import right away on the new Model root node.
Here is the add-in code:
private void loadProjectFromManifest(EA.Repository Repository)
{
try
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "EA Integration Tool files (*.eai)|*.eai";
openDialog.FilterIndex = 1;
openDialog.RestoreDirectory = true;
string manifestFilename = "";
if (openDialog.ShowDialog() == DialogResult.OK)
{
manifestFilename = openDialog.FileName;
}
else
{
return;
}
ImportProjectFromManifest(Repository, manifestFilename);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message + "Failed to load manifest file.");
}
}
public static void ImportProjectFromManifest(EA.Repository Repository, string manifestFilename)
{
string error = "";
try
{
string line;
Repository.EnsureOutputVisible("Script");
Repository.ClearOutput("Script");
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(manifestFilename);
EA.Project eaProject = Repository.GetProjectInterface();
EA.Package basePackage = Repository.GetContextObject() as EA.Package;
while ((line = file.ReadLine()) != null)
{
//load the xmi file in the project under the selected root node
if (line != "")
{
error = "";
Repository.WriteOutput("Script", "Importing " + line, 0);
error = eaProject.ImportPackageXMI(basePackage.PackageGUID, line, 0, 0);
Repository.WriteOutput("Script", "Error returned: " + error, 0);
basePackage.Update();
}
}
file.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message + "Error while loading manifest file " + error);
}
Repository.Models.Refresh();
Repository.RefreshModelView(0);
Repository.WriteOutput("Script", "Finished!", 0);
Repository.BatchAppend = false;
}
The output, for every XMI file in the manifest, is this:
Error returned: Error:
Code = 0x800c0006
Source = Line : 0; Char : 0
Error Description = The system cannot locate the object specified.
I have tried looking for more information regarding this issue but there doesn't seem to be any. The "object" which the system cannot found is not specified, and I am not sure what I mush Refresh/Update/other in order to get the ImportPackageXMI function to work in a reliable way.
The command works when I open an existing EAP file and import on an existing model, but not 100% of the time.
Any ideas on how to get this to work properly?