Shape connectors in Visio

*爱你&永不变心* 提交于 2019-12-04 01:54:52

问题


I'm writing an Add-In to Visio 2010 in Studio 2010 on C#. I need to read a diagram currently opened in Visio. I know how to read shapes of the diagram.

The question is

  1. if I have a shape object, which properties can give me coordinates of the shape on the page and other shapes (if any), the current one is connected with,
  2. if I have a connector object, which properties can give me shapes it connects and direction of the connection.

回答1:


Connections in Visio are handled through Connect objects. Each shape has a collection of incoming connect objects and outgoing connect objects. Their names are FromConnects and Connects, respectively.

Each connect object has a FromSheet and ToSheet property, which are just pointers to Shape objects, the FromSheet shape being the shape that connects to the ToSheet shape.

So, if you have a square shape (shape1) connected to another square shape (shape2) with a connector line (connector), what you actually have is this: connector is connected to shape1 connector is connected to shape2

So on shape1, you'd look at FromConnects and see one Connects item, with FromSheet referencing connector, and ToSheet referring to shape1. Shape 2 would be the same. If you look at Connects on the connector shape, you'd see the same Connects item, with the same objects referenced.

So figuring out whether shape1 connects to shape2 or vice versa is a matter of looking at the order on connector...Connects object 1 would be the "From" shape and Connects object 2 would be the "To" shape.

Here are two VBA routines that get Incoming and Outgoing glues on a shape you pass in, and return a collection object. I know you said you're using C#, but I do VBA for Visio. The code just illustrates raw connection information. I'd suggest you try stepping around in VBA and see how this all works, because it still confuses me.

Public Function GetShapesThatConnectTo(TheShp As Visio.Shape) As Collection
    Dim Result As Collection
    Set Result = New Collection
    For i = 1 To TheShp.FromConnects.Count
        Result.Add TheShp.FromConnects.Item(i).FromSheet
    Next i
    Set GetShapesThatConnectTo = Result
End Function

Public Function GetWhatShapeConnectsTo(TheShp As Visio.Shape) As Collection
    Dim Result As Collection
    Set Result = New Collection
    For i = 1 To TheShp.Connects.Count
        Result.Add TheShp.Connects.Item(i).ToSheet
    Next i
    Set GetWhatShapeConnectsTo = Result
End Function



回答2:


For coordinates:

foreach (Visio.Page Page in Pages)
{
   Visio.Shapes Shapes = Page.Shapes;
   foreach (Visio.Shape Shape in Shapes)
   {
      double x = Shape.Cells["PinX"].ResultIU;
      double y = Shape.Cells["PinY"].ResultIU;


来源:https://stackoverflow.com/questions/6456831/shape-connectors-in-visio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!