[VBA] Howcome i cant find, gpt4 also dont knew, is there a "search/copy as link" method in the api?

charles c. shared this question 15 days ago
Discussion Open

i wanna implement the bilink as in obsidian.

obviously i could make use of the "search" function to find all the selected text inside a "vault" and write into a .mmap (buildin function of mm of "search").


also i don't see an equivalent to "copy as link" method.


i just need to ask gpt4 to do this, and may be update automatically for some time, and add back the bilinks (i think the search is a 1 way link).


problem: i don't find a "search" method in the api, niether do gpt4 know.


what i guess is, that search method is already a macro itself, made by mindjet using the basics.


any idea?


brining bilink to mm would be revolutionary.


gpt4 suggest me to build it from basics... which of cause i prefer if is there is a build in method.


thanks

Best Answer
photo

hi, this is MMCpAsLinkDIY,


so far it can print the selected topic's GUID and convert to OID (as suggested by Nick).

gpt4 seems didn't have the dictionary of mm's winwrap, some functions are wrong which need human input e.g. it use Utility instead of Utilities.


the code is here:


Option Explicit

Sub Main()
    CopyTopicLink
End Sub

Sub CopyTopicLink()
    Dim selectedTopic As Topic
    Dim topicLink As String
    Dim topicGUID As String
    Dim topicOID As String

    ' Get selected topic
    Set selectedTopic = ActiveDocument.Selection.PrimaryTopic

    ' Get the topic GUID
    topicGUID = selectedTopic.Guid

    ' Print the topic GUID to the Output tab
    Debug.Print "Topic GUID: " & topicGUID

    ' Convert GUID to OID using Application.Utilities.GuidBase64ToRegistry
    topicOID = Utilities.GuidBase64ToRegistry(topicGUID)

    ' Print the topic OID to the Output tab
    Debug.Print "Topic OID: " & topicOID

    ' Generate the topic link
    topicLink = "mm://" & ActiveDocument.Path & ActiveDocument.Name & "#/TopicID=" & topicOID

    ' Copy the topic link to the clipboard
    Call Clipboard.SetData(topicLink)

    ' Print the topic link to the Output tab
    Debug.Print "The topic link: " & topicLink

    ' Add hyperlink to the selected topic using the topicGUID
    selectedTopic.Hyperlinks.AddHyperlinkToTopicByGuid topicGUID, topicLink

    ' Inform the user that the link has been copied to the clipboard
    MsgBox "The topic link has been copied to the clipboard and added as a hyperlink."
End Sub

Replies (1)

photo
2

There are no standalone methods for searching, or for copying as a link. There is the TopicFinder object, which can search the topics of a map for certain conditions and raise a callback event when it finds one. From memory I don't think this is very suitable for searching for embedded text.

You can create a link to a topic by assembling one from its properties. If you look at the construction of a mj-map:// URI, it contains the name of the document with white space and HTML characters encoded, plus the topic GUID converted to a registry format. There is a method in the Utilities class for converting from Base64 (as returned from Topic.Guid) to registry format.

mj-map:///C:\Users\nick\OneDrive\Documents\App%20Studio%20HP\App%20Studio%20KB\(S)%20Content-based%20Apps.mmap#oid={441D8A46-9560-4A76-9B6C-7A9947ACB178}

photo
1

it hurts, my plan to implement bilink will be much easier if "search" and "copy as link" is a build in method. thx

photo
1

thx,

i use a flashcard system called "anki"

i am writing a mindmanager macro that will send a question and answer pair to "ankiconnect", and i wish in the anki

it will automatically link back to mindmanager's topic. (currently doing it by hand. tedious...)

thx

photo
1

hi, this is MMCpAsLinkDIY,


so far it can print the selected topic's GUID and convert to OID (as suggested by Nick).

gpt4 seems didn't have the dictionary of mm's winwrap, some functions are wrong which need human input e.g. it use Utility instead of Utilities.


the code is here:


Option Explicit

Sub Main()
    CopyTopicLink
End Sub

Sub CopyTopicLink()
    Dim selectedTopic As Topic
    Dim topicLink As String
    Dim topicGUID As String
    Dim topicOID As String

    ' Get selected topic
    Set selectedTopic = ActiveDocument.Selection.PrimaryTopic

    ' Get the topic GUID
    topicGUID = selectedTopic.Guid

    ' Print the topic GUID to the Output tab
    Debug.Print "Topic GUID: " & topicGUID

    ' Convert GUID to OID using Application.Utilities.GuidBase64ToRegistry
    topicOID = Utilities.GuidBase64ToRegistry(topicGUID)

    ' Print the topic OID to the Output tab
    Debug.Print "Topic OID: " & topicOID

    ' Generate the topic link
    topicLink = "mm://" & ActiveDocument.Path & ActiveDocument.Name & "#/TopicID=" & topicOID

    ' Copy the topic link to the clipboard
    Call Clipboard.SetData(topicLink)

    ' Print the topic link to the Output tab
    Debug.Print "The topic link: " & topicLink

    ' Add hyperlink to the selected topic using the topicGUID
    selectedTopic.Hyperlinks.AddHyperlinkToTopicByGuid topicGUID, topicLink

    ' Inform the user that the link has been copied to the clipboard
    MsgBox "The topic link has been copied to the clipboard and added as a hyperlink."
End Sub
photo
1

still have to deal /w the path, name.

also, gpt4 didn't knew mm use mj-map://....


but the backbone do work

photo
Leave a Comment
 
Attach a file