David
David

Reputation: 4047

Enterprise Architect Script: using ImportPackageXMI

I'm currently automating the process of importing XMI to Enterprise Architect using EA Script - JScript. I've been able to get definitions from existing packages GUID, Name, path to the package, create package.

The reference API from Sparx can be found here

Here's my current code

guid = "{3EC70CB6-28A1-40ed-ADD5-4B3AF5D89EED}"
Session.Output("GUID = " + guid);
Session.Output("GUID XML = " + project.GUIDtoXML(guid));
Session.Output("XMI file = " + svnPath + xmlPath);
result = project.ImportPackageXMI(project.GUIDtoXML(guid), svnPath + xmlPath, 1, 1);
Session.Output(result);

The following output shows that I got "Unknown package" while calling the API:

GUID = {3EC70CB6-28A1-40ed-ADD5-4B3AF5D89EED}   
GUID XML = EAID_3EC70CB6_28A1_40ed_ADD5_4B3AF5D89EED    
XMI file = D:\svn.xxx.com\yyy\docs\design\technical\class\Administration\SystemParameter.xml    
Unknown package: EAID_3EC70CB6_28A1_40ed_ADD5_4B3AF5D89EED  

I've googled for solution but google only shows about 17 results. The project Vienna in google code helps only a little.

So, does anyone know how to use ImportPackageXMI?

Upvotes: 2

Views: 1700

Answers (1)

Uffe
Uffe

Reputation: 10504

I can't tell from the information you've posted, but is it possible that you're trying to export a package from one project and import it into another?

Regardless of whether you tell EA to StripGUID, the package you import the XMI into must exist in the project, and that's what the PackageGUID specifies.

StripGUID 1 means a complete copy of the package contained in the XMI file is placed in the PackageGUID package. New GUIDs are created for all packages, elements, etc in the XMI file. In older versions of EA, this was the only way to make a deep copy of a package (Copy Package to Clipboard).

StripGUID 0 yields a few different results.

  • If the XMI package has the same GUID as PackageGUID, the current contents of the PackageGUID package are replaced by the XMI contents.
  • If the GUIDs are different:
    • If the XMI package GUID does not exist in the project, the XMI package is placed inside the PackageGUID package.
    • If the XMI package GUID exists, the import fails (conflicting packages).

In all four cases, the PackageGUID package must already exist.

Upvotes: 2

Related Questions