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. Click here to download the BAS file: textobject.BAS
  2. Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.

OR:

  1. Copy the script below.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  4. Press Ctrl+V to paste it into the Script Manager.
  5. Click the Start/Resume icon () in the Script Manager.


 

*********

'Note that lines 46-53 can only be run in Grapher 15 Preview and newer versions

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(2,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 + "]")

	'This example shows how to add text with different fonts
	Shapes.AddText(2,5,"This is some text {\f" + Chr(34) + "Wingdings" + Chr(34) + " in a different font } than the rest.")

	'This example shows how to insert the current date/time with custom formatting
	Shapes.AddText( 2,2,"text with date/time: \dt(""dd-mmm-yy"")")
  
	'This example shows how to insert text as part of a template
	Shapes.AddText(2,1.75,"text with template: {\f""Garamond"" /}\ssbeg(30,-45,left,top) \fs57.143 y\ssend \ssbeg(20,-20,right,bottom) \fs57.143 x\ssend")
  
	'This example shows how to insert a symbol using the symbol fonts
	Shapes.AddText(2,1.5,"text with symbol: \f""GSI Default Symbols"" ")

End Sub

 

Updated February 18, 2019

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.