Python Script Engine  1.0
GL Studio Editor Python Script API
Python Script Engine API Reference Index

Scripting Manual

The Python Script Engine allows the execution of python scripts. These scripts can be used to influence a GL Studio design in multiple ways, including creating objects, adding code and properties, and changing settings for the GL Studio design. The Python Script extension allows users to create scripts that automate common functions within GL Studio, including creating objects and code, and making changes to GL Studio editor and document settings. These scripts can also be mapped to custom toolbar buttons directly within the GL Studio interface, providing a quick and easy way to enact commonly used scripts.

Examples

A few examples to get you familiar with the scripting API.

Start a New Document

1 # import the Editor module
2 import Editor
3 
4 # Create a new Document
5 newDoc = Editor.NewDocument()

Create a Basic GLPolygon

1 # import all referenced modules
2 import Editor
3 import GLPolygon
4 import VertexArray
5 import Vertex
6 
7 # Get the currently open and in focus document
8 currentDoc = Editor.GetCurrentDocument()
9 
10 # Create some vertices to use as the bounds of the GLPolygon
12 verts.Insert(Vertex.Vertex(10, 10, 0, 100, 0, 0, 185))
13 verts.Insert(Vertex.Vertex(210, 10, 0, 100, 0, 0, 185))
14 verts.Insert(Vertex.Vertex(210, 110, 0, 100, 0, 0, 185))
15 verts.Insert(Vertex.Vertex(10, 110, 0, 100, 0, 0, 185))
16 
17 # Create the GLPolygon, passing in the vertices we just created
18 polygon = GLPolygon.GLPolygon(verts)
19 polygon.SetPolygonMode( polygon.POLY_MODE_FILLED )
20 
21 # Add the new GLPolygon to our current Document
22 currentDoc.InsertObject( polygon )
23 
24 # New in GL Studio 6.0.1.
25 # How to create a Yellow GLPolygon from a Python list of Vertices.
26 vertsList = [
27  Vertex.Vertex(50, 50, 0, 200, 220, 0, 255),
28  Vertex.Vertex(120, 50, 0, 200, 220, 0, 255),
29  Vertex.Vertex(120, 120, 0, 200, 220, 0, 255),
30  Vertex.Vertex(50, 120, 0, 200, 220, 0, 255),
31 ]
32 
33 # Create a polygon and set its fill mode to filled.
34 yellowPolygon = GLPolygon.GLPolygon( vertsList )
35 yellowPolygon.SetPolygonMode( yellowPolygon.POLY_MODE_FILLED )
36 
37 currentDoc.InsertObject( yellowPolygon )
38 
39 # Make a larger polygon and set a location.
40 multiPolygon = GLPolygon.GLPolygon([
41  Vertex.Vertex(80, 65, 0, 0, 40, 0, 0),
42  Vertex.Vertex(95, 35, 0, 0, 40, 0, 0),
43  Vertex.Vertex(180, 35, 0, 0, 40, 150, 100),
44  Vertex.Vertex(195, 65, 0, 0, 255, 150, 100),
45  Vertex.Vertex(180, 100, 0, 255, 40, 150, 255),
46  Vertex.Vertex(95, 100, 0, 0, 40, 0, 0),
47  ],
48  Vertex.Vertex(-130,0,0)
49 )
50 # Fill and outline mode, and turn on Gouraud shading
51 multiPolygon.SetPolygonMode( multiPolygon.POLY_MODE_FILL_AND_OUTLINE )
52 multiPolygon.SetShadingMode( multiPolygon.SHADING_GOURAUD )
53 
54 currentDoc.InsertObject( multiPolygon )

Truth Value Checking

1 import Editor
2 import Vertex
3 import VertexArray
4 
5 # Opening two documents, one new document, and one that doesn't exist
6 docExists = Editor.NewDocument()
7 nullDoc = Editor.OpenDocument( "nonExistentDoc.gls" )
8 
9 # Will be True because the document object exists
10 if docExists:
11  print "Document exists."
12 
13 # Will be considered False since the object is null
14 if not nullDoc:
15  print 'Document does not exist'
16 
17 # Creating an empty VertexArray
18 vertexArray = VertexArray.VertexArray()
19 
20 # Will be considered False because the array object is empty
21 if not vertexArray:
22  print 'The array is empty'
23 
24 # Adding a vertex to the array
25 vertex = Vertex.Vertex( 0, 0, 0 )
26 vertexArray.Insert( vertex )
27 
28 # Will now be considered True because the array is not empty
29 if vertexArray:
30  print 'The array is not empty'
31 
32 # Retrieving the document's sound list and adding a sound to it
33 soundList = docExists.GetSoundList()
34 soundList.AddSound( "someSound.mp3" )
35 soundItem = soundList.GetSoundItem( 0 )
36 
37 # The SoundItem exists as long as it's in the SoundList
38 if soundItem:
39  print 'This SoundItem exists'
40 
41 # Once the SoundItem is removed, it is considered null, and therefore false
42 soundList.RemoveSound( soundItem )
43 if not soundItem:
44  print 'This SoundItem no longer exists'

Additional References

See the GL Studio Users Manual as well as the Cpp Tutorial for more information on Custom Script Buttons and examples.