使用 C# 在 Visio 2013 中向 Crow-Entity 添加属性

Add attributes to Crow-Entity in Visio 2013 with C#

我想将一个形状添加到一个现有的组中,我通过主模板删除了一个主模板,该主模板在 Visio 2013 中使用 C# 已经包含大约 4 个子形状。
详细地说,我想向 DBEntity 添加更多属性。 到目前为止,我使用了 Shape 的 class 的 parent-属性,但这总是会破坏现有的组并使其无法使用/取消分组。

using VisioApi = Microsoft.Office.Interop.Visio;


VisioApi.Application application = new VisioApi.Application();
application.Documents.Add(templatePath);
VisioApi.Document crowStencil = application.Documents["DBCROW_M.vssx"];

VisioApi.Master entityMaster = crowStencil.Masters.get_ItemU("Entity");
VisioApi.Master attributeMaster = crowStencil.Masters.get_ItemU("Attribute");

VisioApi.Page page = application.Documents[1].Pages[1];
VisioApi.Shape entityShape = page.Drop(entityMaster, 5.0, 5.0);
VisioApi.Shape attributeShape = page.Drop(attributeMaster, 5.0, 5.2);

// After assigning parent, entityShape isn't grouped anymore
attributeShape.Parent = entityShape;

如何以正确的方式做到这一点?

更新:如回复中所述,Crow 使用容器而不是组

"crow foot" 个形状是在 Visio 2013 中使用 "containers" 实现的。所以你应该使用容器 API 来操纵它们。不要使用 Parent 或分组函数,这些不是您要找的。请改用 ContainerProperties,尤其是 InsertListMember

在此处详细了解什么是 visio 容器,以及如何操作它们: https://msdn.microsoft.com/en-us/library/office/ff959245.aspx

针对您的挑战的即时解决方案:

// add one attribute to entity shape
entityShape.ContainerProperties.InsertListMember(attributeShape, 0);

请注意,M$ 可能有一些恢复旧 ER 图的计划,这可能会导致需要返工 ER 形状。意味着,AFAIU ER 图应该是最终用户解决方案,而不是以编程方式进行操作 - 你似乎正在越过一条凡人不应该越过的线:)