企业建筑师Python脚本 - 在图中添加一个元素
我正在尝试编写一个Python脚本,以便可以在Sparx Enterprise Architect中的图中添加一个元素。
TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80","")
TestDiagEl.ElementID=TestEl.ElementID
TestDiagEl.Update
TestDiag.Update
eaRep.ReloadDiagram(TestDiag.DiagramID)
它似乎不起作用,我在做什么错?
编辑 似乎@Geert是正确的,此外,更新后我没有添加()。
I am trying to write a python script so that I can add an element to a diagram in Sparx Enterprise Architect.
TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80","")
TestDiagEl.ElementID=TestEl.ElementID
TestDiagEl.Update
TestDiag.Update
eaRep.ReloadDiagram(TestDiag.DiagramID)
It doesn't seem to work, what am I doing wrong?
EDIT
It seems that @geert was right, additionally i didnt add () after Update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写代码时,您应该知道每条代码的作用,以及为什么要编写它。
在这种情况下,
在内存中创建一个新的图表对象
元素设置为我的元素的元素元素
将图表对象
保存
在数据库
将图表对象的 中是
testdiag.update
。由于内存中的图表尚不知道新的图表对象,因此您有效地消除了新的图表对象的添加。删除该行,一切都可以。另一个问题是您传递给
duagrabjects.addnew
方法的参数。顶部和底部值应该是正面的,正如您在提供的When writing code you should know what each line of code does, and why you are writing it.
In this case
Creates a new diagramObject in memory
Sets the elementID of the diagramObject to the elementID of my element
Save the diagramObject to the database
Save the current diagram in memory to the database
Get the diagramDetails from the database and show them in the GUI
One problem is the
TestDiag.Update
. Since your diagram in memory doesn't know about the new DiagramObject yet, you are effectively undoing the addition of the new DiagramObject. Remove that line, and all should be OK.Another problem is the parameter you pass to the
DiagramObjects.AddNew
method. The top and bottom values should be positive as you can see in the provided documentation So: