【问题标题】:Adding hyperlinks in element notes Enterprise Architect在元素注释中添加超链接 Enterprise Architect
【发布时间】:2018-06-13 07:39:17
【问题描述】:

我正在开发 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。 请帮忙。提前致谢。

【问题讨论】:

  • 注释中的超链接元素和超链接是有区别的。第一个是 EA.Element,后者只是花哨的文本。
  • @GeertBellekens 谢谢..请问是否可以通过 EA API 在注释中添加超链接
  • 只需检查数据库中 notes 字段的内容,然后执行相同操作。

标签: c# element enterprise-architect


【解决方案1】:

正如 Geert 和 Thomas 建议的那样,如果您只需要在笔记中创建超链接,只需在该单词上添加一个 herf 标签,如下所示

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

notes 中的输出会是这样的

在 API 中,您可以在任何类的 notes 属性中添加链接文本。

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;
        }

【讨论】:

  • 我认为没有必要打电话给Refresh()
  • @GeertBellekens@ThomasKilian@Arshad..谢谢..它工作正常!
【解决方案2】:

我尝试了(按照 Geert 的建议)以下代码 sn-p(对于 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多