Macro "transaction" object coding

  • 1
  • Question
  • Updated 2 years ago
I'm much looking forward to Nick Dufill's MM Macro Masterclass promoted through Olympic, said to be timed for sometime in the not-too-distant future.

Meanwhile, looking again at Mindjet's 2012 API/macro manual, there is what feels like an important reference to the advantages of using a 'transaction object' in some cases. For processing efficiency, this apparently suspends multiple/recursive updates to a map's display, until all of the underlying changes driven by the macro have been completed 'behind the scenes'.

Would any kind person be able to share an example of such macro coding in MM? Google only comes up with rather complicated non-MM examples for very sophisticated database entry routines ...

With many thanks!

Best wishes,

David
London

      
Photo of David Abrahams

David Abrahams

  • 46 Posts
  • 4 Reply Likes

Posted 2 years ago

  • 1
Photo of Nick Duffill

Nick Duffill, Champion

  • 515 Posts
  • 172 Reply Likes
Hello David

The module on transactions needs a bit more work so was not included in the preview. You are correct in stating that transactions suspend the UI while they are running, which makes a significant difference to performance, especially if you are adding or updating topics. To use a transaction, you create one for a document, start it, and wait for it to finish. In the meantime, the transaction executes the handler procedure, which is identified by naming it after the transaction object. While it seems strange for the code to sit in a loop waiting for an event to complete, the advantage is the suspension of UI updates.

Option Explicit
Dim WithEvents m_Trans As Transaction ' Transaction object

Sub Main
    Dim m_Document As Document

    Set m_Document = AllDocuments.Add ' start a new document
    Set m_Trans = m_Document.NewTransaction("My transaction")

     ' Kick off transaction
    If Not m_Trans Is Nothing Then
        m_Trans.Start
        Wait(0.1)
        ' Wait for it to finish
        While m_Trans.IsExecuting
            Wait (0.1)
        Wend
        Set m_Trans = Nothing
     End If

     Set m_Document = Nothing

End Sub

Sub m_trans_Execute(ByVal m_Document As Document)
 ' Update the document inside the transaction event, while
 ' map updates to the user interface are suspended
    Dim m_Topic As Topic

    m_Document.CentralTopic.Text = "New document"

    ' Add a subtopic to the central topic
    Set m_Topic = m_Document.CentralTopic.AddSubTopic("New topic")
    m_Topic.Task.Priority = mmTaskPriority1 ' set priority 1 map marker

End Sub
Photo of David Abrahams

David Abrahams

  • 46 Posts
  • 4 Reply Likes
Well, Nick, it's not often I resort to using the word "cool" in public (being a Brit and clearly not cool enough myself), but this is (a) most helpful and (b) pretty cool.

Thanks very much. Doubtless the course will demystify further. For now this beginner can attest: it works!

Best wishes,

David
London