[Macros] How do I print large mindmaps on DIN A4?

  • 1
  • Question
  • Updated 4 years ago
My goal is to print even large mindmaps to DIN A4 without having the font decreased in a way that is suitable to not be able to read it anymore.

  1. My idea is to start at the center and unfold level 1. Virtually print that and verify whether it's font size is above a certain threshold, so it is still readable on DINA4. 
  2. Unfold more and more levels and do that each time until the current level creates a picture that - being printed on DIN A4 - is well readable(as defined by the user). 
  3. Then save it as the first image. 
  4. Then go the first subtopic that has a + to it, create a new temporary main topic out of it and repeat the same procedure with it. 
  5. Then go to the next subtopic.

I have never coded in VisualBasic, but this requires recursion. Is that possible in VB?

How do I get started, is there something like that already done or which script is the closest that I can modify?
Photo of Kurt Sennerich

Kurt Sennerich

  • 7 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Nick Duffill

Nick Duffill, Champion

  • 508 Posts
  • 169 Reply Likes
Hello Kurt

Yes, this is possible. VBA supports recursion, and there is a graphic export method which will create a bitmap.

I am not sure how you will measure font legibility in this bitmap, though.
Photo of Kurt Sennerich

Kurt Sennerich

  • 7 Posts
  • 0 Reply Likes
Thank you Nick.
Photo of Nick Duffill

Nick Duffill, Champion

  • 508 Posts
  • 169 Reply Likes
Hello again Kurt

Here is a sample of a recursive routine in MindManager's VBA-compatible scripting language. This example sets the visible topics down to a specified level in the map.

Recursive routines can work from the centre of the map outwards, or from the outside inwards by swapping the order of the per-topic processing and the iteration over subtopics. Processing of floating topics and callout topics can be included, noting that the central topic does not have callouts.

If you are printing out sections of a map, it may be worth leaving in the route to the central topic, so that the context of a section can easily be seen.

I hope this helps - good luck with the programming.


Option Explicit
Sub Main
    Call ExpandTo(ActiveDocument.CentralTopic, 3)
End Sub

Sub ExpandTo(ByVal m_Topic As Topic, ByVal i_Level As Integer)
    If m_Topic.Level < i_Level Then
        m_Topic.SetLevelOfDetail(1) ' show subtopics
    ElseIf Not m_Topic.IsCentralTopic Then ' do not set LoD=0 on central topic
        m_Topic.SetLevelOfDetail(0)
    End If

    Dim m_Subtopic As Topic
    For Each m_Subtopic In m_Topic.AllSubTopics
        Call ExpandTo(m_Subtopic, i_Level)
    Next
End Sub


Photo of Kurt Sennerich

Kurt Sennerich

  • 7 Posts
  • 0 Reply Likes
Okay, this sets the level of detail. But how could I determine whether it is still readable on print? As you said regarding "Virtually print that and verify whether it's font size is above a certain threshold, so it is still readable on DINA4.": "I am not sure how you will measure font legibility in this bitmap, though.".
Photo of Kurt Sennerich

Kurt Sennerich

  • 7 Posts
  • 0 Reply Likes
I proceeded extending your script. It works in general, do you spot the mistakes that do not add (Seite ) to further submaps?

Also, it marks "ActiveDocument.GraphicExport.AddTopic(hauptthema)" as no linked object after some time. Why is that?

Also, how do you close the newly generated map without destroying it when it's necessary for linking?

Public anzahl As Integer
Public Const ebene = 3
Public hauptthema As Topic
Public Felder
Public X As Integer
Public Dateiname As String


Option Explicit
Sub Main
    anzahl = 0
    'ebene = 3

    Set hauptthema = ActiveDocument.CentralTopic
    Set Felder = Array("<", ">", "|", "/", "*", "\", "?", """")
    Dateiname = hauptthema.Text
    For X = LBound(Felder) To UBound(Felder)
        Dateiname = Replace(Dateiname, Felder(X), "_", 1)
    Next X



    Call Erweitern(hauptthema, ebene)

    Call ErweiternHauptkarte(hauptthema, ebene)
    ActiveDocument.GraphicExport.Reset()
    ActiveDocument.GraphicExport.AddTopic(hauptthema)
    ActiveDocument.GraphicExport.ExportZoomed(Dateiname & " - " & (anzahl + 1) & ".jpg",mmGraphicTypeJpeg,1)

End Sub

Sub Erweitern(ByVal internesThema As Topic, ByVal ZielEbene As Integer)
    If internesThema.Level = ebene And internesThema.SubTopics.Count > 0 Then
        anzahl += 1
        'Debug.Print "Neues Karte mit " internesThema.Text & ": " & internesThema.Level & " (" & anzahl & ")"

        Dim HilfsKarte As Document
        Set HilfsKarte = Documents.Add
        HilfsKarte.CentralTopic.Xml = internesThema.Xml
        Debug.Print "Neue Karte mit " & internesThema.Text & " beginnen ( " & HilfsKarte.CentralTopic.Text & " )"

        HilfsKarte.CentralTopic.Text = internesThema.Text & " (Seite " & anzahl & ")"
        internesThema.Text = internesThema.Text & " (Weiter auf Seite " & anzahl & ")"
        'HilfsKarte.CentralTopic.SetLevelOfDetail(ebene)
        Dim tt As Topic
        Set tt = HilfsKarte.CentralTopic.AddBalancedSubTopic("Test")
        tt.Delete()
        'HilfsKarte.Selection.Set(HilfsKarte.CentralTopic)
        HilfsKarte.GraphicExport.Reset()
        HilfsKarte.GraphicExport.AddTopic(HilfsKarte.CentralTopic)
        If anzahl < 10 Then
            HilfsKarte.GraphicExport.ExportZoomed(Dateiname & " - 0" & anzahl & ".jpg",mmGraphicTypeJpeg,1)
            Else
            HilfsKarte.GraphicExport.ExportZoomed(Dateiname & " - " & anzahl & ".jpg",mmGraphicTypeJpeg,1)
        End If

        HilfsKarte.GraphicExport.Reset()

        Call Erweitern(HilfsKarte.CentralTopic,ebene)

    End If

    If internesThema.Level < ZielEbene Then
        internesThema.SetLevelOfDetail(1) ' show subtopics
    ElseIf Not internesThema.IsCentralTopic Then ' do not set LoD=0 on central topic
        internesThema.SetLevelOfDetail(0)
    End If

    Dim Unterthema As Topic
    For Each Unterthema In internesThema.AllSubTopics
        Call Erweitern(Unterthema, ZielEbene)
    Next
End Sub

Sub ErweiternHauptkarte(ByVal internesThema As Topic, ByVal ZielEbene As Integer)
    If internesThema.Level < ZielEbene Then
        internesThema.SetLevelOfDetail(1) ' show subtopics
    ElseIf Not internesThema.IsCentralTopic Then ' do not set LoD=0 on central topic
        internesThema.SetLevelOfDetail(0)
    End If

    Dim Unterthema As Topic
    For Each Unterthema In internesThema.AllSubTopics
        Call ErweiternHauptkarte(Unterthema, ZielEbene)
    Next
End Sub
(Edited)
Photo of Kurt Sennerich

Kurt Sennerich

  • 7 Posts
  • 0 Reply Likes
Nick, what are your ideas?