Using Grapher Objects

To access Grapher commands from your script you must create a Grapher Application object. To create an Application object, call the CreateObject function with "Grapher.Application" as the argument. Every object has properties and methods associated with it. Properties are values describing the state of an object. Methods are actions an object can perform. Access properties and methods by typing the name of an object variable, followed by a period, followed by the property or method name.

You can use object properties as you would use variables: assign values to properties, branch based on the value of a property, or use the value of a property in calculations. An object's methods are called as you would call subroutines and functions. Use the return values from methods the same as you would use return values from functions.

When you "drill through" the object hierarchy, you can store references to intermediate objects in variables, or you can string together long sequences of object references. For example, you can set the default font for a plot document in a single line:

'Assume "grf" is a variable holding a reference

'to the Application object

 grf.Documents.Item(1).DefaultFont.Bold = True

 

Alternatively, you can store each intermediate object in variables as you traverse the object hierarchy:

'Assume "grf" is a variable holding a reference

'to the Application object

 Set docs = grf.Documents

 Set plot = docs.Item(1)

 Set font = plot.DefaultFont

 font.Bold = True

 

The second form - storing intermediate objects - is more efficient if you are performing several actions with the same object. A third alternative is to use the WITH…END

WITH statement:

'Assume "grf" is a variable holding a reference

'to the Application object

 With grf.Documents.Item(1).DefaultFont

  .Bold = True

  .Size = 12

  .Color = grfColorHotPink

 End With

See Also

Scripter BASIC Language

Object Hierarchy

Object List