Page 1 of 1

A Macro in Vbs to Automatically insert Bookmarks = Pages

Posted: Sat Jun 30, 2007 5:51 pm
by Ed Grossheim
Hi:

If anyone can suggest a brighter approach to accomplishing this, get back.
This illustrates one way, and I am probably overlooking a smart approach!

6/30/2007 12:32:43 PM
Subject: Writing a Macro to Automatically insert a series of BookMarks.
===========
Situation: I am editing a 200 line program..

I want to automatically insert bookmarks when I load my program, so that If I GoToBookMark6 I will be on Page 6 of my document (of course BookMark2 is Page 2).

When I open my program to edit, At the top I have comment'd in the name of the Bookmark-inserting macro
That I will run on this script, after I open the document.
I then copy the full path name to the system clipboard and pull down Macro/Execute Script/ and paste into the window and hit run.

e.g. my path/file name is:
C:\Program Files\Zeus\zScript\ED'S ZEUS SCRIPTS\LESSONS\SET BOOKMARKS 1 - 6 on First 6 pages.vbs

=====================================

I am using Courier New Size 11 Font. I have a given screen size.

You may have to edit the macro with different line numbers.

Macro Script in Vbs:

Code: Select all

Function key_macro()
    call zeus.screen_update_disable
    X = 20

    call zeus.set_line_pos(X,1)
    call zeus.BookMarkDrop1

    X = X+39
    call zeus.set_line_pos(X,1)
    call zeus.BookMarkDrop2

    X = X+39
    call zeus.set_line_pos(X,1)
    call zeus.BookMarkDrop3

    X = X+39
    call zeus.set_line_pos(X,1)
    call zeus.BookMarkDrop4

    X = X+39
    call zeus.set_line_pos(X,1)    
    call zeus.BookMarkDrop5

    X = X+39
    call zeus.set_line_pos(X,1)
    call zeus.BookMarkDrop6

    call zeus.screen_update_enable
    call zeus.screen_update
End Function

key_macro() 'run the macro
===============
Of course I have Key bound BookMarkX (to keys).

It works! -- Ed :D

Posted: Fri Oct 26, 2007 12:43 am
by jussij
If anyone can suggest a brighter approach to accomplishing this, get back.

Below is what I think is slightly improved macro as it automatically figures out the page size ;)

Code: Select all

Function key_macro()
    zeus.cursor_save()

    ' Remove the current bookmarks
    zeus.BookMarkRemoveAll()

    ' Figure out the page length
    zeus.MoveDocumentStart()
    zeus.MovePageEnd()
    PageLength = zeus.get_line_pos()

    DocumentLength = zeus.get_line_count()

    '
    ' Drop the 6 bookmarks
    '
    LineNumber = 1 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop1
    end if

    LineNumber = 2 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop2
    end if

    LineNumber = 3 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop3
    end if

    LineNumber = 4 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop4
    end if

    LineNumber = 5 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop5
    end if

    LineNumber = 6 * PageLength + 1

    if LineNumber < DocumentLength then
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkDrop6
    end if

    zeus.cursor_restore()
End Function

key_macro() 'run the macro
Here is an version that drops the alternative set of bookmarks:

Code: Select all

Function key_macro()
    zeus.cursor_save()

    ' Remove the current bookmarks
    zeus.BookMarkRemoveAll()

    ' Figure out the page length
    zeus.MoveDocumentStart()
    zeus.MovePageEnd()
    PageLength = zeus.get_line_pos()

    DocumentLength = zeus.get_line_count()

    zeus.screen_update_disable()

    ' drop bookmarks at every page
    for LineNumber = PageLength + 1 to DocumentLength step PageLength
        zeus.set_line_pos(LineNumber)
        zeus.BookMarkToggle()
    next

    zeus.screen_update_enable()
    zeus.screen_update()

    zeus.cursor_restore()
End Function

key_macro() 'run the macro
But to navigate to these bookmarks you need to use the Edit Bookmarks, View Bookmarks menu.

Cheers Jussi

Ooops I missed the notification!

Posted: Wed Oct 31, 2007 12:01 am
by Ed Grossheim
10/30/2007 7:00:10 PM

Wow! It looks like some good work Jussi. I will be checking it out in the next few days.

Thanks,
Ed