使用 C# 在 vi​​sio 中创建形状

Creating Shapes in visio using c#

您好,我需要开发一个用于在 visio.I 中创建图表对象的插件,我能够创建顶部形状,但不能创建其派生类型。 对于 EG 我可以使用 c# 在 vi​​sio 中创建开始事件,但无法创建消息类型或其他类型的开始事件

在上图中我有 3 个启动事件,添加了 BPMN 启动事件并且它的 属性 Trigger/Result 选项已更改

Start Event - Multiple

Start Event - Message

Start Event - None

但以上3个形状均来自Start Event。如何创建 Message start 事件或 Multiple start 事件等

我正在使用

在 vi​​sio 中创建形状
            Visio.Master shapetodrop = Masters.get_ItemU(@"Start Event");
            Visio.Shape DropShape = ActivePage.Drop(shapetodrop, x, y);
            DropShape.Name = name;
            DropShape.Text = name;

但这只会创建开始事件、如何创建消息开始事件、多个开始事件等

我会在VBA告诉你答案,希望你能转换成C#?

Microsoft 以他们的智慧为 BPMN 创建了相当复杂的形状,因此,一旦您设置了 EventType,可能的 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

在 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;

                        }
}

而且我可以获得消息开始事件。像这样可以为一个shape的所有属性赋值。