【问题标题】:Creating Shapes in visio using c#使用 c# 在 vi​​sio 中创建形状
【发布时间】:2015-10-07 10:19:22
【问题描述】:

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

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

开始事件 - 多个

开始事件 - 消息

开始事件 - 无

但以上 3 种形状均来自 Start Event。如何创建消息启动事件或多重启动事件等。

我正在使用 visio 中创建形状

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

但这只会创建 Start Event ,如何创建 Message Start EVent ,Multiple Start Event 等

【问题讨论】:

    标签: c# visio bpmn visio2013


    【解决方案1】:

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

    我可以得到消息开始事件。像这个值一样可以为一个形状的所有属性赋值。

    【讨论】:

      【解决方案2】:

      我会用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
      

      【讨论】:

      • 感谢您的回复 :) :)
      猜你喜欢
      • 1970-01-01
      • 2019-05-02
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 2017-05-03
      相关资源
      最近更新 更多