【问题标题】:How do I get shapes in a swimlane shape object from visio automation?如何从 visio 自动化获取泳道形状对象中的形状?
【发布时间】:2012-07-27 01:42:55
【问题描述】:

我正在使用办公自动化将 visio 文件转换为指定的 xml 格式流程图,我需要使用泳道数据作为工作流过程的容器。那么我怎样才能得到workflow shapes and swimlane之间的关系呢?

代码

IVisio.Shape shape = o as IVisio.Shape;

double width = shape.Cells["Width"]
        .Result[Microsoft.Office.Interop.Visio.VisUnitCodes.visMillimeters];
double height = shape.Cells["Height"]
        .Result[Microsoft.Office.Interop.Visio.VisUnitCodes.visMillimeters];
double pinX = shape.Cells["PinX"]
        .Result[Microsoft.Office.Interop.Visio.VisUnitCodes.visMillimeters];
double pinY = shape.Cells["PinY"]
        .Result[Microsoft.Office.Interop.Visio.VisUnitCodes.visMillimeters];

【问题讨论】:

    标签: c# automation ms-office visio


    【解决方案1】:

    返回与传入和传出连接关联的形状的 ID。

    using Visio = Microsoft.Office.Interop.Visio;
    visioObj = (Visio.Application)                  
         System.Runtime.InteropServices.Marshal.GetActiveObject("Visio.Application");
    
    Array ids = shape.ConnectedShapes(Visio.VisConnectedShapesFlags
            .visConnectedShapesAllNodes, "");
    
    // Using first item and get name   
    string name = visioObj.ActivePage.Shapes[ids.GetValue(0)].Name;
    

    【讨论】:

    • 感谢@jones,我找到了解决方案。您的方法也许可以得到由动态连接器连接的形状。
    【解决方案2】:

    要查找容器关系可以使用 API 与此方法:

    public class ShapeWrapper
    {
        public IVisio.Shape Shape { get; set; }
    
        private List<ShapeWrapper> children = new List<ShapeWrapper>();
        public List<ShapeWrapper> Children { get { return this.children; } }
    
        public ShapeWrapper(IVisio.Shape shape)
        {
            Shape = shape;
        }
    }
    
    private void FindChildren(ShapeWrapper shapeWrapper, 
                                  List<IVisio.Shape> addedShapes)
    {
        IVisio.Selection children = shapeWrapper
           .Shape.SpatialNeighbors[
                (short)IVisio.VisSpatialRelationCodes.visSpatialContain, 
                0,
                (short)IVisio.VisSpatialRelationFlags.visSpatialFrontToBack];
    
        foreach (IVisio.Shape child in children)
        {
            if (!addedShapes.Contains(child))
            {
                 //MessageBox.Show(child.Text);
                 ShapeWrapper childWrapper = new ShapeWrapper(child);
                 shapeWrapper.Children.Add(childWrapper);
    
                 FindChildren(childWrapper, addedShapes);
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      您使用 PackagePart 的数据创建 XML 文档。您需要特别注意管理您创建的特定类型 XML 文档的模式的 XML 名称空间。 您创建一个包含 XML 的新文件并将该文件保存到包中的某个位置。 在新的 PackagePart 和 Package 或其他 PackagePart 对象之间创建必要的关系。 您更新需要参考新零件的任何现有零件。例如,如果您将新的页面内容部分(新页面)添加到文件中,您还需要更新页面索引部分(/visio/pages/pages.xml 文件)以包含有关新页面的正确信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多