Enterprise Architect 15.2.1554:JavaScript脚本添加图例条目失败求助
Enterprise Architect 15.2.1554:JavaScript脚本添加图例条目失败求助
我最近在做Enterprise Architect的脚本开发,参考相关思路后,现在能成功把图例添加到目标图表里,但图例里的条目怎么都加不进去,实在找不到问题所在,来求助大家!我用的是EA版本15.2.1554。
下面是我的JavaScript脚本代码:
function out() { let string = ""; for (let i = 0; i < arguments.length; i++) { string += JSON.stringify(arguments[i], null, 2) + " "; } Session.Output(string); } function addLegendEntries(legendGUID, arr=[{ 'BackgroundColor': -1, 'Stereotype' : 'Stereotype'}]){ let description = ""; let customPropertyIndex = 0; arr.forEach( ({BackgroundColor, Stereotype}) => { description += "@PROP=@NAME="+Stereotype+"@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#="+BackgroundColor+";#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT="+customPropertyIndex++ +"@ENDPRMT;@ENDPROP;" }); description += "@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;" const sqlInsertStmt="INSERT INTO t_xref " + "(" + "Client," + "XrefID," + "Type," + "Name," + "Visibility," + "`Partition`," + "Supplier," + "Description" + ") " + " VALUES (" +"'"+legendGUID+ "'," + "'{"+ generateGUID() +"}'," + "'element property'," + "'CustomProperties'," + "'Public'," + "'0'," + "'<none>'," + "'"+description+"'" + ");" out(sqlInsertStmt); out(Repository.SQLQuery(sqlInsertStmt)); } function addLegend(diagramID, arr=[{ 'BackgroundColor': -1, 'Stereotype': 'Stereotype'}]) { Repository.EnsureOutputVisible("Script"); Repository.ClearOutput("Script"); var pkg as EA.Package; pkg = Repository.GetTreeSelectedPackage(); elements = pkg.Elements; var legend = elements.AddNew('Diagram Legend', 'Text'); legend.Subtype = 76; legend.Update(); var diagram as EA.Diagram; diagram = Repository.GetDiagramByID(diagramID); Session.Output(diagram.Name); diagramObjects = diagram.DiagramObjects; diagramObject = diagramObjects.AddNew("l=100; r=100; t=100; b=500;", ""); addLegendEntries(legend.ElementGUID, arr); diagramObject.ElementID = legend.ElementID; diagramObject.Update(); diagram.Update(); } Repository.EnsureOutputVisible( "Script" ); Repository.ClearOutput("Script"); const diagram = Repository.GetDiagramByGuid("{4FA59731-72DF-402c-AF60-1C3381BC2052}"); // Get the current diagram out(diagram.DiagramID); addLegend(diagram.DiagramID, collectColorsInDiagram(diagram)); Repository.ReloadDiagram(diagram.DiagramID); out("Done");
脚本执行后生成的SQL语句如下:
INSERT INTO t_xref (Client,XrefID,Type,Name,Visibility,Partition,Supplier,Description) VALUES ('{9CCF46B8-D221-41b1-B1B9-EF7072547F74}','{cb940358-f76f-9fdd-dfca-d4537143e394}','element property','CustomProperties','Public','0','<none>', '@PROP=@NAME=ArchiMate_Grouping@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=13458026;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=0@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=15528442;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=1@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16777184;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=2@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Capability@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=16443110;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=3@ENDPRMT;@ENDPROP;@PROP=@NAME=ArchiMate_Grouping@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=13434880;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=4@ENDPRMT;@ENDPROP;@PROP=@NAME=@ENDNAME;@TYPE=LEGEND_OBJECTSTYLE@ENDTYPE;@VALU=#Back_Ground_Color#=-1;#Pen_Color#=16777215;#Pen_Size#=1;#Legend_Type#=LEGEND_OBJECTSTYLE;@ENDVALU;@PRMT=5@ENDPRMT;@ENDPROP;@PROP=@NAME=Legend@ENDNAME;@TYPE=LEGEND_STYLE_SETTINGS@ENDTYPE;@VALU=@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;');
我检查了一下,这个SQL语句好像没有生效,但EA的DBError.txt里也没有任何错误信息,实在摸不着头脑,有没有大佬能帮忙分析下问题出在哪?
备注:内容来源于stack exchange,提问作者Matt Andruff
相关产品推荐
相关产品推荐

