在元素注释中添加超链接 Enterprise Architect

Adding hyperlinks in element notes Enterprise Architect

我正在研究 Enterprise Architect C# 插件。我正在尝试通过加载项将超链接添加到元素注释中的另一个包,如下所示:

我在这里找到了在元素中添加超链接到包的代码:https://www.sparxsystems.com/forums/smf/index.php?topic=4068.0 并尝试了以下代码:

                    EA.Package parentPkg = Session.Repository.GetPackageByID(currentPackage.ParentID);//target package
                    hyperlink = currentPackage.Elements.AddNew("$package://"+parentPkg.PackageGUID, "Text"); //adding hyperlink
                    hyperlink.Update();
                    hyperlink.Subtype = 19; 
                    hyperlink.Update();
                    hyperlink.Notes = parentPkg.Name;
                    hyperlink.Update();
                    demoElement.Notes = "test for packages hyperlinks" + hyperlink; //demo element's notes must contain hyperlink to target package
                    mobjElement.Update();

这里显示的不是超链接,而是System.__ComObject。 请帮忙。提前致谢。

我尝试(按照 Geert 的建议)以下代码片段(对 Perl 感到抱歉):

my $e = $rep->getElementByGuid("{92EF2B52-B75E-454d-AD03-5BDC12256A36}");
$e->{notes} = "<a href=\"$package://{81657422-5D41-4dbf-9210-461DF67FD2C2}\"><font color=\"#0000ff\"><u>Link name</u></font></a>";
$e->Update();

只需替换 GUID 和显示名称,您就有了指向包的超链接。请注意,上面的字符串有一些转义字符,所以这里是原始文本:

<a href="$package://{81657422-5D41-4dbf-9210-461DF67FD2C2}"><font color="#0000ff"><u>Link name</u></font></a>

正如 Geert 和 Thomas 所建议的那样,如果您只需要在注释中制作 hyperlink,只需添加一个 herf 标签 ti,如下所示

This is a <a href="$element://{64162D99-026B-40b3-914C-2CC009943540}"><font
     color="#0000ff"><u>Hyperlink</u></font> </a> Example

注释中的输出会像

在 API 中,您可以在任何 class.

的注释 属性 中添加 link 文本
switch ( treeSelectedType )
    {
        case otElement :
        {
            // Code for when an element is selected
            var theElement as EA.Element;
            theElement = Repository.GetTreeSelectedObject();
            theElement.Notes="This is a <a href=\"$element://{700ED461-FAC6-4097-AFF5-5F4787AD99CB}\"><font color=\"#0000ff\"><u>Hyperlink</u></font></a>  Example";
            theElement.Update();
            theElement.Refresh();



            break;
        }