Tutorial on Automating Logos4+ with ComApi in VBA

2»

Comments

  • Dylan Rondeau
    Dylan Rondeau Member, Logos Employee Posts: 1,401

    This does sound like a Verbum issue.

    This should be fixed in 5.2a SR-3. Please let us know if the script now works correctly with Verbum. [:)]

    Dylan Rondeau, Software Tester

    Enable Logging: Mac | Windows (Right-click "Save As...")

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    This does sound like a Verbum issue.

    This should be fixed in 5.2a SR-3. Please let us know if the script now works correctly with Verbum.

    i am not a Verbum user, but Fr. Devin Roza is a Verbum user.

    Thanks Dylan!!!

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    This should be fixed in 5.2a SR-3. Please let us know if the script now works correctly with Verbum. Smile

    Yes, it now works perfectly. Thank you.

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    Have any of you put together VBA code to let you paste simply a Bible verse from a specific translation? Or at least from your highest rated Bible of a certain Bible datatype? It seems that the CopyBibleVerses function doesn't work that way, as it only takes your highest prioritized Bible. I've tried, for example: app.DataTypes.GetDataType("BibleLXX").ParseReference("Gen 1:1") is returning text from my top English Bible. Interestingly, when I look in the VBA Locals window, I can see that Logos is correctly recognizing BibleLXX as a dataset type (it correctly sets the SortTitle to "Bible (LXX-R)", for example).

    (FYI, my goal is to write code to select a Bible passage in Word, create a table with three columns, in which the code would put the Hebrew, LXX, and English translation).

    BTW, looking through the forum for hits for API, I've seen this particular request to just use the API to write code to insert a Bible verse from a specific translation has been made about 3 or 4 different times, and the best answer I've seen so far is that it's not possible with the API... but I find that hard to believe. Is that the case? Thanks.

  • JimTowler
    JimTowler Member Posts: 1,383 ✭✭✭

    Hi all. I've just found this thread on the API. I played with it for some weeks when it was new and then never went back and did much with it. I really wanted it to directly support pasting commands to the cmd box but it does not.

    Anyway, this has inspired me to try again as the last I did was about 2 weeks ago when I installed Visual Studio to this laptop after not having it anywhere for way too long. I did little more than a few buttons to start Logos running, but it was nice to see it again and see Logos 5 pop up on command.

    I'll post here or maybe a new thread if or when I have something interesting or useful ...

  • Pieter J.
    Pieter J. Member Posts: 533

    I tried it several ways and experienced the same problem: Default Bible Text as output for CopyBibleVerses.GetText but correct DataType in the watch window. I browsed through the Logos4Lib with ObjectBrowser and saw that most Properties are read-only. The only way I see that this could be done is wit:

    • LogosDataType.ParseReference
    • LogosDataType.ScanForReferences
    • LogosDataTypes.LoadReference
    • LogosDataType.GetDataType
    • LogosApplication.ExecuteUri

    I tried the following as a quick solution, but the ExecuteUri also defaults to the last used settings although I specified the DataType

        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleBHS.Ge1.1"
        Sleep 1000
        SendKeys "%P"
        Sleep 1000
        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleKJV.Ge1.1"
        Sleep 2000
        SendKeys "%P"
        Sleep 1000
        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleLXX.Ge1.1"
        Sleep 2000
        SendKeys "%P"
        

    I also tried several different entrypoints to the problem with no positive results:


        Dim CBV      As LogosCopyBibleVerses
        Dim BVR      As LogosCopyBibleVersesRequest
        Dim LDTR     As LogosDataTypeReference
        Dim LDT       As LogosDataType

        Set CBV = App.CopyBibleVerses
        Set BVR = CBV.CreateRequest


        Set LDT = App.DataTypes.GetDataType("BibleBHS")
        Set LDTR = LDT.ParseReference("Ge1.1")

        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)


        Set LDTR = App.DataTypes.LoadReference("BibleBHS.Ge1.1")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

        Set LDTR = App.DataTypes.GetDataType("BibleBHS").ParseReference("Ge1.1")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

     

  • Pieter J.
    Pieter J. Member Posts: 533

    Have any of you put together VBA code to let you paste simply a Bible verse from a specific translation? Or at least from your highest rated Bible of a certain Bible datatype? It seems that the CopyBibleVerses function doesn't work that way, as it only takes your highest prioritized Bible. I've tried, for example: app.DataTypes.GetDataType("BibleLXX").ParseReference("Gen 1:1") is returning text from my top English Bible. Interestingly, when I look in the VBA Locals window, I can see that Logos is correctly recognizing BibleLXX as a dataset type (it correctly sets the SortTitle to "Bible (LXX-R)", for example).

    (FYI, my goal is to write code to select a Bible passage in Word, create a table with three columns, in which the code would put the Hebrew, LXX, and English translation).

    BTW, looking through the forum for hits for API, I've seen this particular request to just use the API to write code to insert a Bible verse from a specific translation has been made about 3 or 4 different times, and the best answer I've seen so far is that it's not possible with the API... but I find that hard to believe. Is that the case? Thanks.

    See a possible Temporary solution at end.

    The only entrypoints to the problem I could find seems to be:

    • LogosApplication.ExecuteUri
    • LogosDataType.ParseReference
    • LogosDataType.ScanForReferences
    • LogosDataType.GetDataType
    • LogosDataTypes.LoadReference

    because all other properties are read-only.

    Test Results:

    • LogosApplication.ExecuteUri
      • CopyBibleVerses Window defaults to last used Resource and not the DataType specified in the uri

        Code used to test:

        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleBHS.Ge1.1"
        Sleep 1000
        SendKeys "%P"
        Sleep 1000
        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleKJV.Ge1.1"
        Sleep 2000
        SendKeys "%P"
        Sleep 1000
        App.ExecuteUri "logos4:CopyBibleVerses;ref=BibleLXX.Ge1.1"
        Sleep 2000
        SendKeys "%P"

    None of the following seems to work either: Actually we don't need to test all permutations of code, I just did it to see if there is a specific entrypoint needed that maybe solves the problem.

    • LogosDataType.ParseReference
    • LogosDataType.GetDataType
    • LogosDataTypes.LoadReference

       Code used to test:

        Set LDT = App.DataTypes.GetDataType("BibleBHS")
        Set LDTR = LDT.ParseReference("Ge2.2")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

        Set LDTR = App.DataTypes.LoadReference("BibleBHS.Ge1.1")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

        Set LDTR = App.DataTypes.GetDataType("BibleBHS").ParseReference("Ge1.1")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

        Set LDTR = App.DataTypes.LoadReference("BibleBHS.Ge1.1")
        BVR.Reference = LDTR
        Debug.Print CBV.GetText(BVR)

    I did not test LogosDataType.ScanForReferences because in a way it's tested with the above.

    I can see a slow but working temporary solution to the problem through using SendKeys.

    PseudoCode:

    • Use ExecuteUri to open CopyBibleVerses to Reference
    • Press the Tab key 5 times
    • Press Enter
    • Type the Resource
    • Press Enter
    • Press Alt+P (%P) to Copy to Word
    • Repeat for each Resource

    Use the WinApi sleep between steps to slow down execution if needed { Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) }

    This will render a horizontal list for the Reference from each Resource

  • Pieter J.
    Pieter J. Member Posts: 533

    If the following is against any EULA, please inform me so that I can remove the post. I prefer to stay with the eula.

    Function LoadLayout(LayoutName As String) As Boolean

    You need to know the LayoutName to use this. Just thought I'll post a quick solution to get the LayoutNames from Logos. I only show how to get info you may need with a purpose. Remember, don't work with sql if you don't know what you are doing. You may end up breaking Logos. I find this rather helpfull to import stuff into word, excel and some other programs. I can not garantee that this will always work in the future, Logos may decide to change the Folder Structure or to put a password on databases.

    1. Download and install the SQLite ODBC Driver
    2. Add an ADODB Reference in VBA (Microsoft ActiveX Data Objects 6.1 Library) I think any version from 2 would work.
    3. Add a Class Named "CDataBaseHelper"
    4. Create a form with
    • a ListBox named list1 and
    • a ComboBox named combo1 and
    • a CommandButton named cmdLoad

    PASTE INTO CDataBaseHelper:

    1. Dim conn As ADODB.Connection  
    2. Dim RS As ADODB.Recordset  
    3. Dim Path As String  
    4. Dim UserId As String  
    5.    
    6. Enum LOGOSDATABASES  
    7.     DB_LAYOUTS = 0  
    8.     DB_NOTES = 1  
    9. End Enum  
    10.   
    11. Public Sub LogIn(ByVal LogosDir As String, ByVal UserName As String)  
    12.     Path = LogosDir  
    13.     'Get the Users Id  
    14.     Set conn = New Connection  
    15.     Set RS = New ADODB.Recordset  
    16.       
    17.     conn.Open "Driver={SQLite3 ODBC Driver};Database=" & Path & "\Users\UserManager.db"  
    18.     RS.Open "Select * From users Where LogosUserName = '" & UserName "'", conn  
    19.     UserId = RS.Fields("userid").Value  
    20.     RS.Close  
    21.     conn.Close  
    22. End Sub  
    23.   
    24. Public Sub ListDirect(ByVal db As LOGOSDATABASES, ByVal Obj As Object)  
    25.     If Not (LoggedIn) Then Exit Sub  
    26.     Set conn = New Connection  
    27.     Set RS = New ADODB.Recordset  
    28.     Select Case db  
    29.         Case DB_LAYOUTS  
    30.             conn.Open "Driver={SQLite3 ODBC Driver};Database=" & Path & "\Documents\" & UserId & "\LayoutManager\layouts.db
    31.             RS.Open "Select * From Layouts Where IsDeleted=0", conn 
    32.             While Not (RS.EOF) 
    33.                 Obj.AddItem RS.Fields("Title").Value 
    34.                 RS.MoveNext 
    35.             Wend 
    36.         Case DB_NOTES 
    37.              conn.Open "Driver={SQLite3 ODBC Driver};Database=" & Path & "\Documents\" & UserId & "\Documents\Notes\notes.db
    38.             RS.Open "Select * From NotesDocuments Where IsDeleted=0", conn 
    39.             While Not (RS.EOF) 
    40.                 Obj.AddItem RS.Fields("Title").Value 
    41.                 RS.MoveNext 
    42.             Wend 
    43.      
    44.     End Select 
    45.      
    46.     RS.Close 
    47.     conn.Close 
    48. End Sub 
    49.  
    50. Private Function LoggedIn() As Boolean 
    51.     If Path = "" Or UserId = "" Then  
    52.         LoggedIn = False  
    53.         Else  
    54.         LoggedIn = True  
    55.     End If  
    56. End Function  

    PASTE INTO UserForm (and enter your Logos Path and your UserName as parameters)

    1. Private Sub cmdLoad_Click()  
    2.     Dim db As New CDataBaseHelper  
    3.     Dim sPath As String  
    4.     Dim sUserName As String  
    5.       
    6.     sPath = ""  
    7.     sUserName "LogosUserName "  
    8.       
    9.     db.LogIn sPath, sUserName
    10.     db.ListDirect DB_LAYOUTS, combo1  
    11.     db.ListDirect DB_NOTES, list1  
    12. End Sub