如何在 Visio 中读取形状的属性
我有以下任务。我正在 Studio 2010 中的 C# 上编写 Visio 2010 的加载项。 假设我打开了一个图表。在此图中我有任何类型的形状(让我们尝试从一开始就管理一种形状)。问题是我如何读取这个形状的任何属性?我应该使用哪个 API?
基本算法:
- 扫描打开的文档中的形状
- 如果文档中存在任何形状,则返回所有形状的数组(或列表)(如果当前文档中没有形状,则返回 null)
- 运行形状数组并读取任何属性每个元素(如果有机会编写/修改属性就太好了)
(代码示例将不胜感激)
I have the following task. I'm writing an Add-In for Visio 2010 on C# in Studio 2010.
Let's say that I have a diagram opened. And I have a shape of any kind in this diagram (let's try to manage one shape for the begining). The question is how can I read any properties of this shape? Which API should I use?
Basic algorithm:
- Scan opened document for shapes
- If there are any shapes in document, then return an array (or a list) of all shapes (null is returned in case of no shapes in current document)
- Run over shapes array and read any property for each element (that would be great to have a chance to write/modify property)
(Code example would be greatly appreciated)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您所说的属性指的是形状数据,它曾经在 UI 中称为“自定义属性”,并且在 API 中仍然以该名称为人所知。
如果您不熟悉 ShapeSheet,您应该首先查看 ShapeSheet 中具有自定义属性的形状,以了解如何定义属性。请参阅“ShapeSheet 发生了什么?”了解如何在 Visio 2010 中打开 Shapesheet
。以下示例程序应该可以帮助您入门。此示例假设您的电脑上安装了 Visio Primary Interop Assembly并且您已在项目中包含了 Microsoft.Office.Interop.Visio 的引用者。
I assume that by properties you are referring to Shape Data, which used to be called Custom Properties in the UI and is still know by that name in the API.
If you are not familiar with the ShapeSheet you should have look at a shape with custom properties in the ShapeSheet first to see how the properties are defined. See "What happened to the ShapeSheet?" to learn how to open the Shapesheet in Visio 2010.
The following example program should get you started. This example assumes that you have the Visio Primary Interop Assembly installed on you PC and that you have included a referee to Microsoft.Office.Interop.Visio in your project.
我编写了一个库,使这变得更容易
检索多个形状的属性:
props中存储的返回值将是一个字典列表。每个字典对应于指定形状的属性。属性的名称是字典中的键。
要获取第一个形状的“Foo”属性...
它检索包含公式和形状的对象。属性这些方面的结果:
I wrote a library that makes this a easier
To retrieve the properties for multiple shapes:
The return value stored in props will be a list of dictionaries. Each dictionary corresponds to the properties of the specified shapes. The names of the properties are the keys in the dictionary.
To get the "Foo" property for the first shape...
which retrieves an object which contains the Formulas & Results for these aspects of a property:
对于所有稍后在这个问题上需要代码帮助的人:
To all those, who will need code help later on this question: