Macros - How to and examples

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Brett
    Indigo Rose Staff Member
    • Jan 2000
    • 2001

    Macros - How to and examples

    Well, one of the so far largely overlooked features of AMS40 is its Macro support. I want to start a thread here for those VBScript gurus out there who want to get involved in extending AMS40's functionality through macros.

    All of AMS40's macro support goes through the Macro Editor. To see the Macro Editor, choose Tools > Macros... from the menu. This will open the Macro Editor screen. This is where you will do all of your macro work in AMS40.

    AMS40 uses the SAX Basic Engine for its macro support. SAX basic is very close to VBA in nature. It is much more powerful than VBScript, but uses the same syntax. If you have used VBScript or Visual Basic, SAX Basic will be very familiar to you.

    If you want to learn more about the language and the macro editor itself, see the Help menu within the macro editor.

    AMS40 exposes a very robust COM Automation interface. This means that it exposes its methods and data structures for you to manipulate with Visual Basic, Visual C++, or any other programming tool that supports COM Automation (aka ActiveX). The COM model and all of the methods and properties are outlined in the "COM Automation Reference.doc" document that is located in the Docs subfolder of teh AutoPlay Media Stduio 4.0 folder on your system.

    This document along with the SAX language help will be your roadguide to making cool AMS40 macros. Well, enough background for now, let's get into things...

    One really useful tool in the macro editor is the object browser. You can open the object browser from the button on the toolbar that looks like a box (to the right of the Print icon). This browser allows you to see all of the classes and functions exposed to the macro editor.

    The top-most object that you can manipulate in AMS40 is the Document object. From the Document object you can open, save, build, add pages, remove pages, etc., etc. Basically, all of the top level functionality of AMS40.

    For example, one of the properties of the Document is DocumentName. You can use this property to get the name of the currently open document. To see how this works, open the macro editor and paste in the following code:

    <pre>
    Sub Main
    Dim strMsg As String
    strMsg = "You are working on document:" + Chr(10) + Chr(13)
    strMsg = strMsg + DocumentName
    MsgBox strMsg
    End Sub
    </pre>

    Now press the run toolbar button or hit F5 on your keyboard... WOW, the power of it all!!! [img]/ubbthreads/images/icons/smile.gif[/img]

    Actually not too exciting, but it is a starting point. In this thread I will provide examples of useful macros that you can use to extend the functionality of AMS40. I also welcome any and all questions, bug reports, etc. about the macro support. I'll be more than happy to try and help out.

    - Brett
  • Brett
    Indigo Rose Staff Member
    • Jan 2000
    • 2001

    #2
    Re: Macros - How to and examples

    Here is one that shows how to enumerate the objects on the current page:
    <pre>
    Sub Main
    Dim nNumObjectsOnPage As Integer
    Dim nCurrentPage As Integer
    Dim nCounter As Integer
    Dim strMsg As String
    Dim strReturn As String

    strReturn = Chr(10) + Chr(13)

    ' Get the current page...
    nCurrentPage = GetCurrentPageIndex

    strMsg = "The objects on this page are:" + strReturn + strReturn

    ' Run through each object on the page and store its name
    For nCounter = 0 To (Pages(nCurrentPage).ObjectCount-1)
    strMsg = strMsg + Pages(nCurrentPage).Objects(nCounter).GetProperty( "OBJECTNAME") + strReturn
    Next nCounter

    MsgBox strMsg

    End Sub
    </pre>

    - Brett

    Comment

    • Brett
      Indigo Rose Staff Member
      • Jan 2000
      • 2001

      #3
      Re: Macros - How to and examples

      Here's one that makes all of the text objects on the current page into a color that you specify. I have attached the .bas file that can be loaded into the Macro Editor as well as including the code below:
      <pre>
      Sub Main
      ' This code asks you for a color value (integer) and then makes
      ' all text objects on that page the specified color.

      Dim nNumObjectsOnPage As Integer
      Dim nCurrentPage As Integer
      Dim nCounter As Integer
      Dim strColor As String
      Dim nDlgResult As Integer

      Begin Dialog UserDialog 400,105,"Select Text Object Color" ' %GRID:10,7,1,1
      Text 20,14,250,14,"Please enter a color value (integer):",.Text1
      TextBox 20,35,360,21,.txtColor
      OKButton 90,70,90,21
      CancelButton 190,70,90,21
      End Dialog
      Dim dlg As UserDialog
      nDlgResult = Dialog(dlg)

      If(nDlgResult <> 0) Then
      ' OK was pressed, proceed with the operation...
      strColor = dlg.txtColor

      ' Get the current page...
      nCurrentPage = GetCurrentPageIndex

      ' Run through each object on the page to see if it is a text object
      For nCounter = 0 To (Pages(nCurrentPage).ObjectCount-1)
      If Val(Pages(nCurrentPage).Objects(nCounter).GetPrope rty("TYPE")) = amsObText Then
      Pages(nCurrentPage).Objects(nCounter).SetProperty( "TEXTNORMALCOLOR",strColor)
      End If
      Next nCounter

      Refresh
      End If
      End Sub

      </pre>


      11210-tut_change_text_object_color.zip

      Comment

      • Brett
        Indigo Rose Staff Member
        • Jan 2000
        • 2001

        #4
        Re: Macros - How to and examples

        Here is one that may be semi-useful [img]/ubbthreads/images/icons/smile.gif[/img] It creates any number of empty pages in your project for you:
        <pre>
        Sub Main
        ' This macro creates x number of blank pages in a project
        Dim strPageNamePrefix As String
        Dim nNumPagesToAdd As Integer
        Dim nResult As Integer

        Begin Dialog UserDialog 230,147,"Create Empty pages" ' %GRID:10,7,1,1
        Text 20,7,190,14,"Number of pages to create:",.Text1
        TextBox 20,28,190,21,.txtNumPages
        Text 20,63,160,14,"Page name prefix:",.Text2
        TextBox 20,84,190,21,.txtPrefix
        OKButton 20,119,90,21
        CancelButton 120,119,90,21
        End Dialog
        Dim dlg As UserDialog
        nResult = Dialog(dlg)

        If (nResult = 0) Then
        Exit Sub
        End If

        strPageNamePrefix = dlg.txtPrefix
        nNumPagesToAdd = Val(dlg.txtNumPages)

        For i = 1 To (nNumPagesToAdd)
        AddPage (strPageNamePrefix + Str(i),-1)
        Next i

        End Sub

        </pre>

        Comment

        • Carlos
          Indigo Rose Customer
          • Sep 2000
          • 36

          #5
          Re: Macros - How to and examples

          Thanks Brett for the effort.
          Always wanted to know how to use Macros. Useful stuff!

          Comment

          • Brett
            Indigo Rose Staff Member
            • Jan 2000
            • 2001

            #6
            Re: Macros - How to and examples

            If you or anyone else out there has some ideas for useful macros, let me know and together we can work on putting them together for everyone to share. Basically, macros can do most everything that you do in the design environment by hand, but doing it from VB code. This makes it ideal for taking care of redundant, boring tasks. If you find yourself doing something over and over again and wishing that there was a way to automate it, post it here and we'll see what we can do!

            - Brett

            Comment

            • Derek
              Indigo Rose Customer
              • May 2001
              • 1254

              #7
              Re: Macros - How to and examples

              Well in that case - is it poss to write the code once for an action and get other instances to use it?

              ie:
              You have 40 pages where you require it (Page.On Show) to read a txt file and display the text (or part of) in a Text Objext etc.

              Perhaps do this once and set the other pages to call this from SAX
              This could be used for so many Objects/instances
              -
              = Derek
              ["All glory comes from daring to begin" - fortune cookie]

              Comment

              • Lorne
                Indigo Rose Staff Member
                • Feb 2001
                • 2729

                #8
                Re: Macros - How to and examples

                Not exactly...that would require the macros to run at run time. They only run at design time (for several good reasons that I explained in another thread, 'member? [img]/ubbthreads/images/icons/smile.gif[/img]).

                You could write a macro to duplicate the actions in a whole bunch of objects, though...perhaps looking for a pair of target comments like:

                // Begin TEXT_MACRO_CODE

                // End TEXT_MACRO_CODE

                ...with everything in between being replaced with your selected actions...you could probably even build a SAX Basic dialog to let you select the name of the macro.
                --[[ Indigo Rose Software Developer ]]

                Comment

                • Derek
                  Indigo Rose Customer
                  • May 2001
                  • 1254

                  #9
                  Re: Macros - How to and examples

                  Thank you! [img]/ubbthreads/images/icons/smile.gif[/img]

                  Until now, nobody has actually said "They only run at design time"
                  -
                  = Derek
                  ["All glory comes from daring to begin" - fortune cookie]

                  Comment

                  • Lorne
                    Indigo Rose Staff Member
                    • Feb 2001
                    • 2729

                    #10
                    Re: Macros - How to and examples

                    Not true. [img]/ubbthreads/images/icons/smile.gif[/img]
                    --[[ Indigo Rose Software Developer ]]

                    Comment

                    • Derek
                      Indigo Rose Customer
                      • May 2001
                      • 1254

                      #11
                      Re: Macros - How to and examples

                      OOPS! [img]/ubbthreads/images/icons/frown.gif[/img] [Hides head in shame]

                      Sorry Lorne [img]/ubbthreads/images/icons/smile.gif[/img]
                      -
                      = Derek
                      ["All glory comes from daring to begin" - fortune cookie]

                      Comment

                      • Lorne
                        Indigo Rose Staff Member
                        • Feb 2001
                        • 2729

                        #12
                        Re: Macros - How to and examples

                        Heh, no problem, that was kind of obscured in a hijacked thread. [img]/ubbthreads/images/icons/smile.gif[/img]
                        --[[ Indigo Rose Software Developer ]]

                        Comment

                        • Derek
                          Indigo Rose Customer
                          • May 2001
                          • 1254

                          #13
                          Re: Macros - How to and examples

                          Can we have a Macro [pleeeeease] that will provide a list of all the Variables used in a project [and what page they are on too would be really sweet]? [img]/ubbthreads/images/icons/smile.gif[/img]
                          -
                          = Derek
                          ["All glory comes from daring to begin" - fortune cookie]

                          Comment

                          • Corey
                            Indigo Rose Staff Alumni
                            • Aug 2002
                            • 9745

                            #14
                            Re: Macros - How to and examples

                            You don't write VB Derek? Shocking, I thought you were a MS guru...

                            Corey Milner
                            Creative Director, Indigo Rose Software

                            Comment

                            • Derek
                              Indigo Rose Customer
                              • May 2001
                              • 1254

                              #15
                              Re: Macros - How to and examples

                              lol - I was never any good with VB, so I'll leave it to the Guru [img]/ubbthreads/images/icons/smile.gif[/img] ... Brett likes the attention anyways
                              -
                              = Derek
                              ["All glory comes from daring to begin" - fortune cookie]

                              Comment

                              Working...
                              X