Advanced Overview of Scripting
Consider the "FindPrimes" example, where all math on a canvas is checked to see if it is prime. The workflow is as follows:
Step 1: Create/Edit/Modify the canvas -- this is where the user enters some new math.
Step 2: When the button is pressed the contents of the canvas will be serialized into an XML structure. This includes all text, math, the button, and all of the Maple code behind the button. The "canvas" will be passed as an argument to the FindPrimes() procedure, which can use GetMath and GetElements if it wants to inspect any values.
Step 3: A script is created. The script is generated by creating a Script object, and then calling any of the Script object methods such as SetActive, Annotate, and SetMath. This script is finally broken down into a series of XML instructions by calling ToString.
Step 4: In the Maple environment Script commands produce results immediately as they are invoked, but in the Maple Learn environment, no action is taken until the complete script is written and sent back to the Maple Learn interface, at which point the individual script commands are processed. This happens because the FindPrimes button action procedure is processed by a Maple engine in the cloud. This is separate from the returned XML instructions that will be processed in the client, no longer having a connection to Maple.
Here is an example that uses raw script commands to invoke actions that are only understood by the Maple Learn environment. The Command method processes these raw commands into the right format.
RunThis := proc( canvas )
local script := Script();
for local m in GetMath(canvas) do
cv := NewCanvas(["Write an expression", ScriptButton("Test the Script", RunThis, position = [500, 50])]):
A canvas can be created with a script attached so that when the canvas is opened in Maple Learn, the script automatically plays itself.
sc := Script(mode='Learn'):
cv := NewCanvas([ "Main Title", more^2 ], sc ):
Use of Canvas Elements in Maple Library Commands
Return to DocumentTools[Canvas] Overview Page
Download Help Document