Dellenny

Guide me in IT world

Architecture

Approaches to Automatically Generate Visio Diagrams from Text

1. Use Visio + VBA or VSTO (Visual Studio Tools for Office)

You can automate diagram creation using VBA or .NET-based VSTO add-ins.

Example (VBA):

vbaCopyEditSub CreateBasicFlowchart()
    Dim visApp As Visio.Application
    Set visApp = CreateObject("Visio.Application")
    
    Dim visDoc As Visio.Document
    Set visDoc = visApp.Documents.Add("Basic Flowchart.vstx")

    Dim visPage As Visio.Page
    Set visPage = visDoc.Pages(1)

    Dim shpStart As Visio.Shape
    Set shpStart = visPage.Drop(visApp.Documents("Basic Flowchart Shapes.vssx").Masters("Start/End"), 4, 10)
    shpStart.Text = "Start"

    Dim shpProcess As Visio.Shape
    Set shpProcess = visPage.Drop(visApp.Documents("Basic Flowchart Shapes.vssx").Masters("Process"), 4, 7)
    shpProcess.Text = "Step 1"

    visPage.DropConnector shpStart, shpProcess
End Sub

You can parse your textual input (e.g., a simple DSL) and then use VBA/VSTO to build the shapes.


2. Visio API via Power Automate or PowerShell

If you’re in a Microsoft ecosystem, you can use Visio Online APIs with Power Automate or scripts.

PowerShell + COM:

powershellCopyEdit$visio = New-Object -ComObject Visio.Application
$doc = $visio.Documents.Add("")
$page = $visio.ActivePage

3. Use Text-to-Diagram Tools (then Import into Visio)

a. PlantUML + Visio Import

  • Write diagram as PlantUML text
  • Generate SVG/PNG
  • Import into Visio
plantumlCopyEdit@startuml
start
:Check input;
if (Valid?) then (yes)
  :Process data;
else (no)
  :Show error;
endif
stop
@enduml

Generate with:

bashCopyEditjava -jar plantuml.jar diagram.txt

b. Mermaid.js → SVG → Visio

Mermaid syntax is simpler than PlantUML. Use online tools or CLI to generate SVG.


4. Draw.io or Diagrams.net → Visio

  • Generate XML via Draw.io’s format from text
  • Export as .vsdx or import into Visio

5. Custom Parser + Visio SDK

If you want full control:

  1. Write your DSL (e.g., YAML, JSON)
  2. Parse it with a custom app in .NET or Python
  3. Use Visio Interop SDK to draw dynamically

Sample JSON:

jsonCopyEdit{
  "shapes": [
    { "type": "start", "text": "Start", "x": 4, "y": 10 },
    { "type": "process", "text": "Step 1", "x": 4, "y": 7 }
  ],
  "connectors": [
    { "from": 0, "to": 1 }
  ]
}

🔧 Tools & Libraries

  • Visio Interop Assembly (Microsoft.Office.Interop.Visio)
  • PlantUML / Mermaid
  • Draw.io CLI
  • Power Automate with Visio Online
  • Graphviz (DOT format) → Import into Visio via intermediate SVG

✅ Recommendations

Use CaseRecommended Tool
Flowcharts, swimlanesPlantUML → Visio
Infrastructure / architectureYAML/JSON → Visio via SDK
Business workflowsPower Automate + Visio Online
Lightweight needsDraw.io + export

Discover more from Dellenny

Subscribe to get the latest posts sent to your email.