是否可以在 Visio 中从 Stencil 获取形状?
假设我在 Visio 中打开了一个文档,并且在 Visio 加载项代码中有一个指向该文档的指针。是否可以从模板中获取以下信息:
- 形状名称(我的意思是类型,而不是唯一名称)
- 图片
据我所知,图表和模板是当前文档的一部分。那么如何从文档指针移动到可用的模板表单呢?
(我所说的模板是指左侧的面板,用户可以在其中看到所有可用的形状)
提前致谢。 担
Let's say I have a document opened in Visio and I have a pointer to this document in my Visio Add-In code. Is it possible to derive the following information from stencil:
- Name of Shape (I mean type, not a unique name)
- Picture
As far as I know, diagram and stencil are parts of current document. So how do I move from document pointer to available stencil forms?
(By stencil I mean the panel on the left hand side where user can see all shapes available)
Thanks in advance.
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以拖放到页面上的形状的定义称为“母版”。将形状和母版视为类似于 OOP 中的实例化对象和类。 Visio 文档有一个 Masters 集合。您在左侧窗格中查看的母版可能不在活动文档的母版集合中。左侧的每个窗格都是一个不同的文档,称为模板。使用模板创建新图表时,可以打开多个模具。要了解有关文档、模板、母版和形状之间关系的更多信息,请参阅 开发 Microsoft Visio 解决方案的第 3 章。
要访问打开的模板之一,请使用应用程序的文档集合。然后,您可以使用文档的母版集合访问各个母版。 Master 对象有一个 名称 和图标 属性。
在 .Net 中使用 Icon 属性存在许多挑战。 Icon 属性是一个 IPictureDisp,您需要找到一种方法将其转换为可以在 .Net 中使用的图像类型。中的 IPictureDispToImage 方法VB6 库是一种方法,但它仅适用于 32 位可执行文件。
如果您在进程外(即从外部可执行文件而不是加载项)调出,则 Icon 属性将引发 COM 异常。我从未在 C# 中实际使用过它,因此我不确定 IPictureDisp 属性是否可以在 COM 和 .Net 之间进行封送。
如果您无法使用 Icon 属性,您仍然可以通过调用 ExportIcon 方法将图标写入文件或剪贴板。
以下代码显示了如何获取主控的名称以及如何将主控图标导出到文件。
The definition of shapes you can drop on the page is called a Master. Think of Shapes and Masters as analogous to instantiated objects and classes in OOP. A Visio document has a Masters collection. The masters you look at on the left pane are probably not in the Masters collection of the active document. Each pane on the left is a different document, referred to as a Stencil. Multiple stencils can be opened when you create a new diagram using a template. To learn more about the relationship between Documents, Stencils, Masters and Shapes see Chapter 3 of Developing Microsoft Visio Solutions.
To access one of the open stencils use the Application's Documents collection. You can then get to the individual Masters using the Document's Masters collection. The Master object has a Name and an Icon property.
There are a number of challenges in using the Icon property in .Net. The Icon property is an IPictureDisp, you will need to find a way of converting this to a image type you can use in .Net. The IPictureDispToImage method in the VB6 library is one way but it only works in 32bit executables.
The Icon property will throw an COM exception if you callout out of process, i.e. from an external executable as opposed to an add-in. I have never actually used it from C# so I'm not sure if the IPictureDisp property can be marshaled between COM and .Net.
If you can't use the Icon property you could still get the icon by calling the ExportIcon method to write the icon to a file or the clipboard.
The following code shows how get the name of a master and how to export the master icon to a file.
我明白了:
“docs”数组成员编号中有一个关键点,它们从 1 开始,而不是像数组那样从 0 开始。
谢谢你的帮助。这个问题应该结束了。
担
I got the point:
There is a key point in 'docs' array member numbers, they start from 1, not from 0 like it is used to be for arrays.
Thank you for help. This question is supposed to be closed.
Dan