To implement a feature for an Enterprise Architect (EA) Add-In I needed to show a dialog to the user, which allows him to select a package. The repository class provides a method called InvokeConstructPicker to do so. It seemed to be pretty simple. It was, but you have to consider a small detail, which I did not do in the beginning.

InvokeConstructPicker (string ElementFilter) takes an element filter as argument and returns an int. To filter for packages only you have to pass IncludedTypes=Package as argument. As I do so, I expected to get the Id of the selected package as return value and tried to load the package as follows.

var result = repository.InvokeConstructPicker("IncludedTypes=Package");
var package = repository.GetPackageByID(result);

GetPackageByID with the result of the InvokeConstructPicker method failed. After a quick debugging session I recognized, that the Id that gets returned by the InvokeConstructPicker method is the Id of the element which is not the same as the Id of the package. Having realized that, I fixed the code as follows.

var result = repository.InvokeConstructPicker("IncludedTypes=Package");
var element = repository.GetElementByID(result);
var package = repository.GetPackageByGuid(element.ElementGUID);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.