2016-05-20 3 views
0

私はプログラム内のデータベースから「アクション」をエクスポートするために、プログラムでシェイプを接続するためにAutoConnectメソッドを使用しています。図形が元の状態に戻ると、AutoConnectメソッドは爆弾を爆発させます。私は誰かがこれを達成するために別の方法にアイデアを持っているのだろうかと思っていた。プログラムで形状を元に戻す

private void connectExportedActions(DataTable dt, Page page, Document currentStencil) 
    { 
     List<string> Connectors = new List<string>(); 
     Shape parallelShape; 
     Shape successShape; 
     Shape unsuccessShape; 
     Shape timeoutShape; 
     Master connector; 
     Shape timeout; 
     string timeoutDisplay; 


     foreach (DataRow row in dt.Rows) 
     { 

      Shape shape = page.Shapes.get_ItemFromID((int)row["ShapeID"]); 

      if (row["acdParallelActionDefID"].ToString() != "" && row["acdParallelActionDefID"].ToString() != "NULL") 
      { 
       Connectors.Add("Parallel Connector"); 
      } 
      if (row["acdPositiveActionDefID"].ToString() != "" && row["acdPositiveActionDefID"].ToString() != "NULL") 
      { 
       Connectors.Add("Successful Connector"); 
      } 
      if (row["acdNegativeActionDefID"].ToString() != "" && row["acdNegativeActionDefID"].ToString() != "NULL") 
      { 
       Connectors.Add("Unsuccessful Connector"); 
      } 
      if (row["acdTimeOutActionDefID"].ToString() != "" && row["acdTimeOutActionDefID"].ToString() != "NULL") 
      { 
       Connectors.Add("Timeout Connector"); 

      } 

      foreach (string conn in Connectors) 
      { 

       foreach (Master mst in currentStencil.Masters) 
       { 
        if (mst.Name == conn) 
        { 
         Console.WriteLine(String.Format("Action Name: {0}, ActionDefID: {1}", row["acdName"].ToString(), row["ActionDefID"].ToString())); 
         switch (conn) 
         { 
          case "Parallel Connector": 
           connector = mst; //page.Drop(mst, 0, 0); 
           parallelShape = getShape(dt, row, "ActionDefID", "acdParallelActionDefID", page); 
           **shape.AutoConnect(parallelShape, VisAutoConnectDir.visAutoConnectDirRight, connector);** 
           break; 
          case "Successful Connector": 
           connector = mst; //page.Drop(mst, 0, 0); 
           successShape = getShape(dt, row, "ActionDefID", "acdPositiveActionDefID", page); 
           **shape.AutoConnect(successShape, VisAutoConnectDir.visAutoConnectDirDown, connector);** 
           break; 
          case "Unsuccessful Connector": 
           connector = mst; // page.Drop(mst, 0, 0); 
           unsuccessShape = getShape(dt, row, "ActionDefID", "acdNegativeActionDefID", page); 
           //Console.WriteLine(String.Format("Action Name: {0}, ActionDefID: {1}", row["acdName"].ToString(), row["ActionDefID"].ToString())); 
           **shape.AutoConnect(unsuccessShape, VisAutoConnectDir.visAutoConnectDirLeft, connector);** 
           break; 
          case "Timeout Connector": 
           timeout = page.Drop(mst, 0, 0); 
           timeoutShape = getShape(dt, row, "ActionDefID", "acdTimeOutActionDefID", page); 
           timeoutDisplay = "T = " + row["acdDeadlinePeriod"].ToString() + " days"; 
           timeout.Cells["Prop.Display"].FormulaU = "\"" + timeoutDisplay + "\""; 
           **shape.AutoConnect(timeoutShape, VisAutoConnectDir.visAutoConnectDirLeft, timeout);** 

           timeout.Delete(); 

           break; 
         } 


        } 
       } 
      } 
      Connectors.Clear(); 
     } 
    } 

    private Shape getShape(DataTable dt, DataRow row, string fieldname, string rowcolumn, Page page) 
    { 
     DataRow[] foundRows; 

     foundRows = dt.Select(fieldname + " = " + row[rowcolumn].ToString()); 

     int ShapeID = (int)foundRows[0]["ShapeID"]; 

     Shape shape = page.Shapes.get_ItemFromID(ShapeID); 

     return shape; 
    } 
+1

。全部を絞り込むことはできますか? –

+0

基本的には、オートコネクトメソッドを使用してシェイプを結合しています。私が自分自身にシェイプを接続しようとすると、Autoconnectメソッドが爆発します。 Autoconnectメソッドを使用せずにプログラムでこれを行う方法はありますか? – user2048126

答えて

0

私はあなたがやっているのと同じようなことに取り組んでいました。無限ループを避けるために図形が自分自身に接続されないようにしましたが、そうする必要がある場合は、Visio SDKコードサンプルのConnectWithDynamicGlueAndConnectorメソッドがそれを実行できるはずです。

public void ConnectWithDynamicGlueAndConnector(
     Microsoft.Office.Interop.Visio.Shape shapeFrom, 
     Microsoft.Office.Interop.Visio.Shape shapeTo) { 


     if (shapeFrom == null || shapeTo == null) { 
      return; 
     } 


     const string BASIC_FLOWCHART_STENCIL = 
      "Basic Flowchart Shapes (US units).vss"; 
     const string DYNAMIC_CONNECTOR_MASTER = "Dynamic Connector"; 
     const string MESSAGE_NOT_SAME_PAGE = 
      "Both the shapes are not on the same page."; 

     Microsoft.Office.Interop.Visio.Application visioApplication; 
     Microsoft.Office.Interop.Visio.Document stencil; 
     Microsoft.Office.Interop.Visio.Master masterInStencil; 
     Microsoft.Office.Interop.Visio.Shape connector; 
     Microsoft.Office.Interop.Visio.Cell beginX; 
     Microsoft.Office.Interop.Visio.Cell endX; 

     // Get the Application object from the shape. 
     visioApplication = (Microsoft.Office.Interop.Visio.Application) 
      shapeFrom.Application; 

     try { 

      // Verify that the shapes are on the same page. 
      if (shapeFrom.ContainingPage != null && shapeTo.ContainingPage != null && 
       shapeFrom.ContainingPage.Equals(shapeTo.ContainingPage)) { 

       // Access the Basic Flowchart Shapes stencil from the 
       // Documents collection of the application. 
       stencil = visioApplication.Documents.OpenEx(
        BASIC_FLOWCHART_STENCIL, 
        (short)Microsoft.Office.Interop.Visio. 
         VisOpenSaveArgs.visOpenDocked); 

       // Get the dynamic connector master on the stencil by its 
       // universal name. 
       masterInStencil = stencil.Masters.get_ItemU(
        DYNAMIC_CONNECTOR_MASTER); 

       // Drop the dynamic connector on the active page. 
       connector = visioApplication.ActivePage.Drop(
        masterInStencil, 0, 0); 

       // Connect the begin point of the dynamic connector to the 
       // PinX cell of the first 2-D shape. 
       beginX = connector.get_CellsSRC(
        (short)Microsoft.Office.Interop.Visio. 
         VisSectionIndices.visSectionObject, 
        (short)Microsoft.Office.Interop.Visio. 
         VisRowIndices.visRowXForm1D, 
        (short)Microsoft.Office.Interop.Visio. 
         VisCellIndices.vis1DBeginX); 

       beginX.GlueTo(shapeFrom.get_CellsSRC(
        (short)Microsoft.Office.Interop.Visio. 
         VisSectionIndices.visSectionObject, 
        (short)Microsoft.Office.Interop.Visio. 
         VisRowIndices.visRowXFormOut, 
        (short)Microsoft.Office.Interop.Visio. 
         VisCellIndices.visXFormPinX)); 

       // Connect the end point of the dynamic connector to the 
       // PinX cell of the second 2-D shape. 
       endX = connector.get_CellsSRC(
        (short)Microsoft.Office.Interop.Visio. 
         VisSectionIndices.visSectionObject, 
        (short)Microsoft.Office.Interop.Visio. 
         VisRowIndices.visRowXForm1D, 
        (short)Microsoft.Office.Interop.Visio. 
         VisCellIndices.vis1DEndX); 

       endX.GlueTo(shapeTo.get_CellsSRC(
        (short)Microsoft.Office.Interop.Visio. 
         VisSectionIndices.visSectionObject, 
        (short)Microsoft.Office.Interop.Visio. 
         VisRowIndices.visRowXFormOut, 
        (short)Microsoft.Office.Interop.Visio. 
         VisCellIndices.visXFormPinX)); 
      } 
      else { 

       // Processing cannot continue because the shapes are not on 
       // the same page. 
       System.Diagnostics.Debug.WriteLine(MESSAGE_NOT_SAME_PAGE); 
      } 
     } 
     catch (Exception err) { 
      System.Diagnostics.Debug.WriteLine(err.Message); 
      throw; 
     } 
    } 
+0

これは正しい方向に私を考えさせました。ありがとう! – user2048126

0

AutoConnectは、全体の形に接着すると考えることができる動的な接着剤を作成します。しかし、この場合は、代わりにスタティックまたはポイントツーポイントの接着剤を作成したいと考えています。 @bcwhimsは、セルオブジェクトのGlueToメソッドを使用していることを指摘しています。

私は、代替の方法でセル名の構文を使用している、すでに書いたいくつかのコードを追加します:これは、コネクタと、以下の形状が生成された接着剤の処方を示す/終了細胞を始める生成

var shpTarget = vApp.ActivePage.DrawRectangle(1.0, 10.0, 1.5, 9.5); 

    shpTarget.CellsU["FillForegnd"].FormulaU = "THEMEGUARD(RGB(122,201,118))"; 
    shpTarget.CellsU["LineColor"].FormulaU = "THEMEGUARD(RGB(255,255,255))"; 

    shpTarget.AddNamedRow((short)Visio.VisSectionIndices.visSectionConnectionPts, 
          "Top", 
          (short)Visio.VisRowTags.visTagDefault); 
    shpTarget.CellsU["Connections.Top.X"].FormulaU = "Width*0.5"; 
    shpTarget.CellsU["Connections.Top.Y"].FormulaU = "Height"; 

    shpTarget.AddNamedRow((short)Visio.VisSectionIndices.visSectionConnectionPts, 
          "Right", 
          (short)Visio.VisRowTags.visTagDefault); 
    shpTarget.CellsU["Connections.Right.X"].FormulaU = "Width"; 
    shpTarget.CellsU["Connections.Right.Y"].FormulaU = "Height*0.5"; 


    var shpConnector = vApp.ActivePage.Drop(vApp.ConnectorToolDataObject, 1.5, 10.0); 

    var beginCell =shpConnector.CellsU["BeginX"]; 
    var endCell =shpConnector.CellsU["EndX"]; 

    beginCell.GlueTo(shpTarget.CellsU["Connections.Top.X"]); 
    endCell.GlueTo(shpTarget.CellsU["Connections.Right.X"]); 

    shpConnector.CellsU["EndArrow"].FormulaU = "5"; 

を:

読んで(理解)し、また多くのコードを読むために(と理解)するために大量のテキストがある

enter image description here

+0

ありがとう、これは私が正しい方向に向かうために必要な基本的なものです。どうもありがとう! – user2048126

関連する問題