Follow

How can I add a complex text object (multi-line, with symbols or partial formatting) in Grapher via automation?

This article contains a sample script for creating a new plot window and adding multiple complex text boxes. These show how to use multiple lines, how to insert symbols, how to use bold or italic for a portion of the text, how to add the current date and time, how to change the font for some characters in the text string, and how to create a text string with user inputs.

To run this script:

  1. Copy the script below, or click here to download the BAS file: textobject.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

Sub Main
	'Declare the variable that will reference the application
	Dim GrapherApp As Object

	'Creates an instance of the Grapher Application object
	' and assigns it to the variable named "GrapherApp"
	Set GrapherApp = CreateObject("Grapher.Application")

	'Make Grapher visible
	GrapherApp.Visible = True

	'Declare Plot as Object
	Dim Plot As Object

	'Creates a new plot window
	Set Plot = GrapherApp.Documents.Add(grfPlotDoc)

	'Declares Shapes as an object
	Dim Shapes As Object

	'Assigns the Shapes collection to the variable named "Shapes"
	Set Shapes = Plot.Shapes

	'Add a text object that contains two lines
	Shapes.AddText(5,4,"This is a text block" + vbCrLf + "with two rows.")

	'Add another text object that shows how to insert a symbol
	Shapes.AddText(2,6,"This is a bullet \a183 more text")

	'This example shows how to include bold , italics and strikethrough text
	Shapes.AddText(2,1,"This is {\b bold}, {\i italic} and {\strike strikethrough} text.")

	'This example shows how to insert the current date/time
	Shapes.AddText(2,7,"\date  \time ")

	'Insert user input data
	Min = "10"
	Max = "25"
	Shapes.AddText(2,3,"[" + Min + "] to [" + Max + "]")

	'Change font
	Shapes.AddText(2,5,"This is some text {\f" + Chr(34) + "Wingdings" + Chr(34) + " in a different font } than the rest.")


End Sub

 

Updated October 28, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.