我正在使用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。 请帮助。提前谢谢。
答案 0 :(得分:1)
我尝试过(如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>
答案 1 :(得分:1)
正如Geert和Thomas建议的那样,如果你只需要在笔记中添加超链接,只需添加一个herf标签,如下所示
This is a <a href="$element://{64162D99-026B-40b3-914C-2CC009943540}"><font
color="#0000ff"><u>Hyperlink</u></font> </a> Example
并且笔记中的输出将类似于
在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;
}