企业建筑师Python脚本 - 在图中添加一个元素

发布于 2025-01-21 14:42:21 字数 336 浏览 4 评论 0原文

我正在尝试编写一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2025-01-28 14:42:21

编写代码时,您应该知道每条代码的作用,以及为什么要编写它。

在这种情况下,

TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80","")

在内存中创建一个新的图表对象

TestDiagEl.ElementID=TestEl.ElementID

元素设置为我的元素的元素元素

TestDiagEl.Update

将图表对象

TestDiag.Update

保存

eaRep.ReloadDiagram(TestDiag.DiagramID)

在数据库

将图表对象的 中是testdiag.update。由于内存中的图表尚不知道新的图表对象,因此您有效地消除了新的图表对象的添加。删除该行,一切都可以。

另一个问题是您传递给duagrabjects.addnew方法的参数。顶部和底部值应该是正面的,正如您在提供的

TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=20;b=80","")

When writing code you should know what each line of code does, and why you are writing it.

In this case

TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80","")

Creates a new diagramObject in memory

TestDiagEl.ElementID=TestEl.ElementID

Sets the elementID of the diagramObject to the elementID of my element

TestDiagEl.Update

Save the diagramObject to the database

TestDiag.Update

Save the current diagram in memory to the database

eaRep.ReloadDiagram(TestDiag.DiagramID)

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:

TestDiagEl=TestDiag.DiagramObjects.AddNew("l=10;r=110;t=20;b=80","")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文