2012-03-16 20 views
2

Visio図を作成していますが、既存のシェイプが接続されているかどうかを確認する必要があります。私はこれを決めるために3つの方法で方法を書いた。私はこれを直接行うための形状メソッドを見つけることができませんでした。ここに私が思いついたことがあります。私はそれが反復を伴わないので、第3の方法よりも好ましい。これ以上の提案はありますか?Visio - シェイプが接続されているかどうかをチェックする

private bool ShapesAreConnected(Visio.Shape shape1, Visio.Shape shape2) 
    { 
    // in Visio our 2 shapes will each be connected to a connector, not to each other 
    // so we need to see if theyare both connected to the same connector 

     bool Connected = false; 
     // since we are pinning the connector to each shape, we only need to check 
     // the fromshapes attribute on each shape 
     Visio.Connects shape1FromConnects = shape1.FromConnects; 
     Visio.Connects shape2FromConnects = shape2.FromConnects; 

     foreach (Visio.Shape connect in shape1FromConnects) 
     { 
      // first method 
      // for each shape shape 1 is connected to, see if shape2 is connected 
      var shape = from Visio.Shape cs in shape2FromConnects where cs == connect select cs; 
      if (shape.FirstOrDefault() != null) Connected = true; 

      // second method, convert shape2's connected shapes to an IEnumerable and 
      // see if it contains any shape1 shapes 
      IEnumerable<Visio.Shape> shapesasie = (IEnumerable<Visio.Shape>)shape2FromConnects; 


      if (shapesasie.Contains(connect)) 
      { 
       return true; 
      } 
     } 

     return Connected; 

     //third method 
     //convert both to IEnumerable and check if they intersect 
     IEnumerable<Visio.Shape> shapes1asie = (IEnumerable<Visio.Shape>)shape1FromConnects; 
     IEnumerable<Visio.Shape> shapes2asie = (IEnumerable<Visio.Shape>)shape2FromConnects; 
     var shapes = shapes1asie.Intersect(shapes2asie); 
     if (shapes.Count() > 0) { return true; } 
     else { return false; } 

    } 

答えて

1

Visioの2010を使用している場合は、 Shape connectors in Visio

StackOverflowの上の関連する質問もあり参考コネクティビティAPI VisioのMSDNブログ http://blogs.msdn.com/b/visio/archive/2009/09/22/the-visio-2010-connectivity-api.aspx

から

リンクを見てみましょう

+0

私はVisio 2010を使用していませんが、私はugpradeに行くと思います。それは私が今やっているよりもずっと簡単に見えます。ありがとう。 –

関連する問題