2015-10-07 105 views
5

嗨,我需要開發一個插件,用於在visio中創建圖表對象。我能夠創建頂部形狀,但不能創建其派生類型。 爲EG我能夠使用C#在Visio以創造啓動事件,但無法創建消息類型的啓動事件或其他 enter image description here使用c#在visio中創建圖形

在上面的圖片我有3個啓動事件,以及在BPMN啓動事件並將其屬性觸發器/結果選項改爲

啓動事件 - 多

啓動事件 - 消息

開始事件 - 無

但是以上所有3種形狀均來自Start Event。如何創建消息開始的事件或多個開始EVET等

我使用

  Visio.Master shapetodrop = Masters.get_ItemU(@"Start Event"); 
      Visio.Shape DropShape = ActivePage.Drop(shapetodrop, x, y); 
      DropShape.Name = name; 
      DropShape.Text = name; 

創造Visio形狀,但這只是創建啓動事件,如何創建的留言開始時,多啓動事件等

回答

3

迭代在visio

short iRow = (short)Visio.VisRowIndices.visRowFirst; 
      while (shape.get_CellsSRCExists((short)Visio.VisSectionIndices.visSectionProp, iRow, (short)Visio.VisCellIndices.visCustPropsValue, (short)Visio.VisExistsFlags.visExistsAnywhere) != 0) 
      { 
       Visio.Cell c = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionProp, iRow, (short)Visio.VisCellIndices.visCustPropsValue); 
         switch (c.Name) 
         { 
          case "Prop.BpmnTriggerOrResult": 
           shape.Cells[c.Name].FormulaU = "\"" + "Message" + "\""; 
           break; 

         } 
} 

我可以得到消息開始事件。像這個形狀的所有屬性的值都可以分配。

0

我會告訴你在VBA的答案,並期望你可以轉換爲C#?

微軟在創建相當複雜形狀的BPMN自己的智慧,所以,一旦你通過一個形狀的每個屬性設置的事件類型,名單可能TriggerOrResult更新...

Public Sub DropEventShape() 
On Error GoTo errHandler 

'EventType is one of the following : "Start;Start (Non-Interrupting);Intermediate;Intermediate (Non-Interrupting);Intermediate (Throwing);End" 

Const mstName As String = "Start Event" 
Const eventType As String = "Start" 
Const triggerOrResult As String = "Multiple" 

Dim doc As Visio.Document 
Dim stn As Visio.Document 
Dim mst As Visio.Master 

    For Each doc In Application.Documents 
     If doc.Title = "BPMN Shapes" Then 
      Set stn = doc 
      Exit For 
     End If 
    Next 
    If stn Is Nothing Then 
     GoTo exitHere 
    End If 

    Set mst = stn.Masters(mstName) 

Dim shp As Visio.Shape 
Dim x As Double 
Dim y As Double 
    x = Application.ActivePage.PageSheet.Cells("PageWidth").ResultIU * 0.5 
    y = Application.ActivePage.PageSheet.Cells("PageHeight").ResultIU * 0.5 

    Set shp = Application.ActivePage.Drop(mst, x, y) 

Dim iEventType As Integer 
Dim aryEventTypes() As String 

    aryEventTypes = Split(shp.Cells("Prop.BPMNEventType.Format").ResultStr(""), ";") 
    For iEventType = 0 To UBound(aryEventTypes) 
     If aryEventTypes(iEventType) = eventType Then 
      Exit For 
     End If 
    Next 
    shp.Cells("Prop.BPMNEventType").Formula = "=INDEX(" & iEventType & ",Prop.BPMNEventType.Format)" 

Dim iTriggerOrResult As Integer 
Dim aryTriggerOrResults() As String 
    aryTriggerOrResults = Split(shp.Cells("Prop.BpmnTriggerOrResult.Format").ResultStr(""), ";") 
    For iTriggerOrResult = 0 To UBound(aryTriggerOrResults) 
     If aryTriggerOrResults(iTriggerOrResult) = triggerOrResult Then 
      Exit For 
     End If 
    Next 

    shp.Cells("Prop.BpmnTriggerOrResult").Formula = "=INDEX(" & iTriggerOrResult & ",Prop.BpmnTriggerOrResult.Format)" 

exitHere: 
    Exit Sub 
errHandler: 
    MsgBox Err.Description 
    Resume exitHere 
End Sub 
+0

感謝您的回覆:) :) – Arshad