通过C#自动排列visio形状

时间:2012-09-19 08:22:40

标签: c# visio

我在我的C#应用​​程序中使用Microsoft Visio作为COM对象。我想在Visio页面上自动排列形状。我应该为这项任务编码什么?形状是数据库实体。

userView.Shapes.SomeMethod();

userView是COM对象的名称,但SomeMethod应该是什么?

3 个答案:

答案 0 :(得分:3)

我知道这是一个'较老'的问题,但是 我正在做一些非常相似的事情,并设法使用以下代码“自动布局”流程图:

public enum GraphStyles { TopDown, LeftRight };
public void ArrangeGraph(GraphStyles Style)
{
    if (Style == GraphStyles.TopDown)
    {
        // set 'PlaceStyle'
        var placeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLOPlaceStyle).ResultIU = 1;
        // set 'RouteStyle'
        var routeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLORouteStyle).ResultIU = 5;
        // set 'PageShapeSplit'
        var pageShapeSplitCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLOSplit).ResultIU = 1;
    }
    else if (Style == GraphStyles.LeftRight)
    {
        // set 'PlaceStyle'
        var placeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLOPlaceStyle).ResultIU = 2;
        // set 'RouteStyle'
        var routeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLORouteStyle).ResultIU = 6;
        // set 'PageShapeSplit'
        var pageShapeSplitCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
            (short)VisSectionIndices.visSectionObject,
            (short)VisRowIndices.visRowPageLayout,
            (short)VisCellIndices.visPLOSplit).ResultIU = 1;
    }
    else { throw new NotImplementedException("GraphStyle " + Style.ToString() + " is not supported"); }
    VisApp.ActivePage.Layout();
}

希望这能节省一些时间。 我花了一段时间才弄明白。

我正在使用visio 2010和visual studio 2010

答案 1 :(得分:0)

This可能有帮助

相关报价

  

布置页面,母版或组的形状的子集,   建立一个Selection对象,其中要布置的形状是   选中,然后调用Layout方法。如果布局方法是   在Selection对象上执行,对象没有选择形状,   选择页面,主页或组中的所有形状   进行。

编辑:中午和2012-09-21添加了有关LayoutIncremental方法的信息

再看一下对象模型,看起来你想要的方法是LayoutIncremental方法

摘自relevant help topic说:

Page.LayoutIncremental(AlignOrSpace, AlignHorizontal, AlignVertical, SpaceHorizontal, SpaceVertical, UnitsNameOrCode)

答案 2 :(得分:0)

我需要做一些类似的事情..

我使用了Microsofts Glee库进行布局。下载中包含非常好的示例,向您展示如何添加节点和关系并使它们“自动排列”。但请注意,Glee不能免费用于商业用途。

然后我使用此示例将计算出的位置从Glee转换为Visio绘图。

基本上我所做的是将我的所有节点和关系添加到Glee,然后获取节点列表及其位置,并使用第二个链接将它们添加到Visio。

以下是Glee可以做的图表示例:

Glee image example

相关问题