Question for MindManager Macros
We are using MindManager Enterprise Subscription Windows22 version.
<What we are trying to do>
Add the comment KC2 to all topics tagged C2 in the map.
<Symptoms>
Up to the 5th one can be added, but the 6th one causes an error.
<Additional explanation>
1. The operation of selecting commented-out, C2-tagged topics can be performed to the end.
2. When changing not only the comment body, but also the optional arameters such as Author name and date, each operation seems to be counted as one. error occurs when a total of five operations are performed.
3. If you perform an operation to add a subtopic under the same conditions, it appears that adding a subtopic, changing the subtopic's title, and subtopic, and changing the title of the subtopic, each of which seems to be considered one operation. two renamed subtopics are added and one unnamed subtopic is added. The operation stops when two renamed subtopics are added and one unnamed subtopic is added.
The Macro is below .....
'#Language "WWB-COM"
Option Explicit
Sub Main
With ActiveDocument
Dim aSelection As Selection
Set aSelection = ActiveDocument.Selection Dim aTopic As Topic 'Set
aTopic = aSelection.PrimaryTopic Dim KK As Boolean Dim EX As String
'tag name
EX = "C2"
Dim EX2 As String
EX2 = "KC2"
Dim TL As TextLabels
Dim Day As Date
Day = #05/21/2022 14:00:00 PM#
Dim Idx As Long
Dim An As String
Idx = 1
For Each aTopic In ActiveDocument.Range(mmRangeAllTopics,True)
Set TL = aTopic.TextLabels
KK = TL.ContainsTextLabel(EX)
If KK = True Then
'aSelection.Add(aTopic)
'aTopic.AddNewTopic("ww")
aTopic.ReviewComments.Add("")
'An = aTopic.ReviewComments.Item(Idx).AuthorName
'Debug.Print An
'Else
'Debug.Print "No"
End If
Next
End With
End Sub
Hello
The macro with the lines commented out works OK.
However, adding topics to the map while iterating over Document.Range(mmRangeAllTopics) will cause an error. If you insert topics inside this loop, it changes the collection that you are iterating, which will lead to an internal index error. You will need to make a copy of the topics in the range before iterating over them. Then if the topics range in the document changes, it does not cause an error.
E.g.
Dim m_Range As Range
Dim i_1 As Integer
Dim m_Topics() As Topic
Dim m_Topic As Topic
Set m_Range = ActiveDocument.Range(mmRangeAllTopics, True)
ReDim m_Topics(1 To m_Range.Count)
For i_1 = 1 To m_Range.Count
Set m_Topics(i_1) = m_Range.Item(i_1)
Next
' Now iterate over the copy of the range
For Each m_Topic In m_Topics
' add subtopics
Next
Hello
The macro with the lines commented out works OK.
However, adding topics to the map while iterating over Document.Range(mmRangeAllTopics) will cause an error. If you insert topics inside this loop, it changes the collection that you are iterating, which will lead to an internal index error. You will need to make a copy of the topics in the range before iterating over them. Then if the topics range in the document changes, it does not cause an error.
E.g.
Dim m_Range As Range
Dim i_1 As Integer
Dim m_Topics() As Topic
Dim m_Topic As Topic
Set m_Range = ActiveDocument.Range(mmRangeAllTopics, True)
ReDim m_Topics(1 To m_Range.Count)
For i_1 = 1 To m_Range.Count
Set m_Topics(i_1) = m_Range.Item(i_1)
Next
' Now iterate over the copy of the range
For Each m_Topic In m_Topics
' add subtopics
Next
---