如何循环访问 Visio 几何行
How to iterate over Visio Geometry rows
我有兴趣从 Visio 中的形状中查找几何数据(如下所示),以便我可以将其导出到我可以在其他项目中使用的东西。
问题是我希望能够在 Visio 中绘制东西,导出几何数据,然后在不同 formats/applications.
中重复使用这些图像
到目前为止,我已经成功地从我的自定义功能区中为每个形状提取了一些数据,但我似乎无法获得我真正想要的数据。基本上这是通过反复试验(以及大量的智能感知)找到的。
foreach (Visio.Shape shape in Globals.ThisAddIn.Application.ActivePage.Shapes)
{
lstShapes.Items.Add(shape.Text + " (" + shape.Name + ") Type: " + shape.Type + " - Section: " + shape.get_Section(1) + " - GeoCount:" + shape.GeometryCount + " - LayerCount: " + shape.LayerCount);
}
现在我正在研究如何找到所有选定的形状而不是文档中的所有形状,不确定这是否有帮助。我一直在浏览 Visio.Shape
的各种属性,但似乎根本不存在几何数据。
要获取选定的形状,您可以在 Window
上使用 Selection
属性。一旦你掌握了它,你就可以像这样循环遍历形状、部分和行(注意 I'm using LINQPad here,但唯一的区别是你如何获得应用程序):
var vApp = MyExtensions.GetRunningVisio();
var firstComponent = (short)Visio.VisSectionIndices.visSectionFirstComponent;
foreach (Visio.Shape shp in vApp.ActiveWindow.Selection)
{
for (short s = firstComponent; s < firstComponent + shp.GeometryCount; s++)
{
var geoSection = shp.Section[s];
for (short r = 1; r < geoSection.Count; r++)
{
var rt = shp.RowType[s, r];
Enum.GetName(typeof(Visio.VisRowTags), rt).Dump();
//You now have the shape, section and row and, if you want to,
//you can get to cells by using CellsSRC syntax:
//var someCellValue = shp.CellsSRC[s, r, (short)Visio.VisCellIndices.visX].ResultIU;
//How you address the cell will depend on the row type that you're targeting.
}
}
}
如果您将其用于导出,那么您可能还想看看将文档另存为 SVG。以下是一些选项:
- Page.Export
- HTML Export tool 来自@Nikolay
另一种选择可能是查看 Shape 的 Paths / PathsLocal 属性。例如,在您的 foreach 形状内:
for (int x = 1; x <= shp.Paths.Count; x++)
{
Visio.Path p = shp.PathsLocal[x] as Visio.Path;
p.Points(0.1, out Array pntsArr);
pntsArr.Dump();
}
我有兴趣从 Visio 中的形状中查找几何数据(如下所示),以便我可以将其导出到我可以在其他项目中使用的东西。
问题是我希望能够在 Visio 中绘制东西,导出几何数据,然后在不同 formats/applications.
中重复使用这些图像到目前为止,我已经成功地从我的自定义功能区中为每个形状提取了一些数据,但我似乎无法获得我真正想要的数据。基本上这是通过反复试验(以及大量的智能感知)找到的。
foreach (Visio.Shape shape in Globals.ThisAddIn.Application.ActivePage.Shapes)
{
lstShapes.Items.Add(shape.Text + " (" + shape.Name + ") Type: " + shape.Type + " - Section: " + shape.get_Section(1) + " - GeoCount:" + shape.GeometryCount + " - LayerCount: " + shape.LayerCount);
}
现在我正在研究如何找到所有选定的形状而不是文档中的所有形状,不确定这是否有帮助。我一直在浏览 Visio.Shape
的各种属性,但似乎根本不存在几何数据。
要获取选定的形状,您可以在 Window
上使用 Selection
属性。一旦你掌握了它,你就可以像这样循环遍历形状、部分和行(注意 I'm using LINQPad here,但唯一的区别是你如何获得应用程序):
var vApp = MyExtensions.GetRunningVisio();
var firstComponent = (short)Visio.VisSectionIndices.visSectionFirstComponent;
foreach (Visio.Shape shp in vApp.ActiveWindow.Selection)
{
for (short s = firstComponent; s < firstComponent + shp.GeometryCount; s++)
{
var geoSection = shp.Section[s];
for (short r = 1; r < geoSection.Count; r++)
{
var rt = shp.RowType[s, r];
Enum.GetName(typeof(Visio.VisRowTags), rt).Dump();
//You now have the shape, section and row and, if you want to,
//you can get to cells by using CellsSRC syntax:
//var someCellValue = shp.CellsSRC[s, r, (short)Visio.VisCellIndices.visX].ResultIU;
//How you address the cell will depend on the row type that you're targeting.
}
}
}
如果您将其用于导出,那么您可能还想看看将文档另存为 SVG。以下是一些选项:
- Page.Export
- HTML Export tool 来自@Nikolay
另一种选择可能是查看 Shape 的 Paths / PathsLocal 属性。例如,在您的 foreach 形状内:
for (int x = 1; x <= shp.Paths.Count; x++)
{
Visio.Path p = shp.PathsLocal[x] as Visio.Path;
p.Points(0.1, out Array pntsArr);
pntsArr.Dump();
}