PDA

View Full Version : Macros - How to and examples



Brett
09-05-2002, 07:51 PM
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 (http://www.sax.net) 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!!! /ubbthreads/images/icons/smile.gif

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
09-05-2002, 10:04 PM
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

Brett
09-06-2002, 12:37 PM
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 (http://www.indigorose.com/ubbthreads/uploads/11210-tut_change_text_object_color.zip)

Brett
09-06-2002, 01:11 PM
Here is one that may be semi-useful /ubbthreads/images/icons/smile.gif 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>

Carlos
09-08-2002, 04:16 PM
Thanks Brett for the effort.
Always wanted to know how to use Macros. Useful stuff!

Brett
09-09-2002, 03:55 PM
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

Derek
09-09-2002, 04:32 PM
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

Lorne
09-10-2002, 08:24 AM
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? /ubbthreads/images/icons/smile.gif).

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.

Derek
09-10-2002, 11:51 AM
Thank you! /ubbthreads/images/icons/smile.gif

Until now, nobody has actually said "They only run at design time"

Lorne
09-10-2002, 11:57 AM
Not true. (http://www.indigorose.com/ubbthreads/showthreaded.php?Cat=&amp;Board=UBB2&amp;Number=10202&amp;Sear ch=true&amp;Forum=UBB2&amp;Words=SAX&amp;Match=Entire%20Phrase &amp;Searchpage=0&amp;Limit=25&amp;Old=1year&amp;Main=10089) /ubbthreads/images/icons/smile.gif

Derek
09-10-2002, 12:10 PM
OOPS! /ubbthreads/images/icons/frown.gif [Hides head in shame]

Sorry Lorne /ubbthreads/images/icons/smile.gif

Lorne
09-10-2002, 12:22 PM
Heh, no problem, that was kind of obscured in a hijacked thread. /ubbthreads/images/icons/smile.gif

Derek
10-13-2002, 04:27 PM
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]? /ubbthreads/images/icons/smile.gif

Corey
10-13-2002, 05:48 PM
You don't write VB Derek? Shocking, I thought you were a MS guru...

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Derek
10-13-2002, 06:49 PM
lol - I was never any good with VB, so I'll leave it to the Guru /ubbthreads/images/icons/smile.gif ... Brett likes the attention anyways http://www.aozl37.dsl.pipex.com/ams4/icons/wink.gif

Corey
10-13-2002, 07:49 PM
So what if we refer you to a client as an expert consultant and they ask you to write a macro? Hmmmm? Hmmmm?

/ubbthreads/images/icons/smile.gif

That's a joke BTW just in case you weren't sure...

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Worm
01-08-2003, 03:07 PM
Is there a listing somewhere of the GetProperty items?

I cannot seem to find any information on them. What I'm looking for is to get the name of an image object. I believe it's GetProperty("OBJECTNAME") now after reading through this thread. Still, I'd like to see a list of the available items.

Brett
01-08-2003, 08:59 PM
Worm,

Have you checked out the AMS40COM.chm file? It has a list of all of the attributes that you can get for an object.

Worm
01-08-2003, 09:06 PM
Sorry if this has been covered already, but I don't have that file on my system. Is it downloadable?

Worm
01-08-2003, 09:39 PM
I found "COM Automation Reference.doc" in the docs folder, it seems to have the info I need. Is there a CHM?

Lorne
01-09-2003, 08:34 AM
Yes, right in the AutoPlay Media Studio 4.0 folder.

If it isn't there, um, make sure you're running the latest version. /ubbthreads/images/icons/smile.gif

Worm
01-09-2003, 08:50 AM
doh! Found it...

Mee
10-07-2003, 10:23 PM
hi:
i need some help here ...!
i need to get the elapsed time(progress) of a MediaPlayerObject , as i can do with Mp3Player... ?!
i thought i can do it through Macros:
- if this can be done - HOW can i define my own method on the MediaPlayerObject and then i can use as it an action..???
thanks in advance,