DocumentTools[Canvas]
Script
script canvas operations
Calling Sequence
Parameters
Description
List of Script Methods
Examples
Compatibility
Script()
Script(s, options)
s
-
(optional) string, list(string), or existing Script object
mode = ...
(optional) Maple or Learn
size = ...
(optional) [posint,posint] size of canvas
canvas = ...
(option) existing canvas
The Script command creates a new Script object which can be used to perform operations on a Canvas. A "canvas" is both (1) a document template where math can be inserted and acted upon by button clicks within Maple, and (2) the document environment used by Maple Learn.
When used within Maple, each script method, when invoked, immediately applies that action to the current environment. For example, calling SetMath(x^2) will cause x^2 to appear in the currently active math container. At the same time it records the XML script action used by Maple Learn required to invoke the same operation using Maple Learn's scripting language.
A script can be used to populate a canvas, or it can be used to invoke changes to the canvas when a button is clicked. In the Maple Learn environment, when a button is clicked, the current state of the canvas is sent to a Cloud service to run the related command action, which, can apply Script commands, and finally use ToString to extract the script XML and return it back to Maple Learn, where it will perform those script actions in sequence.
The default mode depends on which environment you are running the command in. Use the mode=Learn option to force the operation to generate Learn script commands even though you are in Maple.
In Maple Learn, the canvas is effectively infinite in size, and has pixel resolution. The canvas that is simulated in Maple is a finite grid of 12 rows and 2 columns of hidden containers that are revealed and populated by Script commands. Use the size=[nrows,ncolumns] to specify an underlying grid with more elements.
When an existing script is given as the first argument to the Script constructor, it will copy the XML Maple Learn script into itself.
The canvas=c option can be used to link a script to an existing canvas.
The following is a list of available methods:
Annotate
annotate math
ClearGroup
clear the elements from the active canvas group
Command
append a raw script command
Cursor
cursor movement script command
Highlight
add highlights to a math canvas element
HighlightOff
remove highlights from a math canvas element
SetActive
set the active canvas element
SetChecked
set checkbox
SetMath
set the contents of a math canvas element
SetOption
set canvas or canvas element properties
SetPlot
SetState
SetText
set the contents of a text canvas element
ToString
convert a script object to a XML string
Static Content in a Canvas
In this section we create a canvas with text, and math in columns.
with⁡DocumentTools:-Canvas:
cv≔NewCanvas⁡A Sample Maple Learn Document,Some Text,E=M⁢C2,E,M,C2:
ShowCanvas⁡cv
Script to Populate a Canvas
In this section we create a blank canvas, then add text, and math via script commands.
cv≔NewCanvas⁡:
ShowCanvas⁡cv,size=6,3
s≔Script⁡:
s:-SetText⁡s,A Sample Maple Learn Document,where=30,30,container=textbox
s:-SetText⁡s,Some Text,where=below
s:-SetMath⁡s,E=M⁢C2,where=right
s:-SetActive⁡s,1
s:-SetMath⁡s,E,where=below
s:-SetMath⁡s,M,where=right
s:-SetMath⁡s,C2,where=right
At this point the canvas in this section is the same as the one in the previous section. We can embed the script into a new canvas and watch the actions animate in sequence when deployed to Maple Learn.
cv2≔NewCanvas⁡,s:
ShareCanvas⁡cv2
Script Button
In this section we create a canvas with a procedure that runs a script when a button is clicked.
Check := proc( canvas ) local script := Script(); for local m in GetMath(canvas) do script:-SetActive(script,m); if m:-math = 2 then script:-Annotate(script,"Good job, this is correct"); else script:-Annotate(script,"This is not the answer"); end if; end do; script:-ToString(script); end proc:
cv≔NewCanvas⁡Text⁡Calculate %1:,`%+`⁡1,1,Math⁡,ScriptButton⁡Check,Check:
Raw Script Commands
In this section we generate a script for use in Maple Learn that applies raw script commands to an entered expression.
RunThis := proc( canvas ) local script := Script(); for local m in GetMath(canvas) do script:-SetActive(script,m); script:-Command(script,["COPYDOWN","Left","Left","STOREPOS","Right","MARK","SELECTMARK","PAUSE","BS"]); end do; script:-ToString(script); end proc:
cv≔NewCanvas⁡Write an expression,ScriptButton⁡Test the Script,RunThis,position=500,50:
ShareCanvas⁡cv
insertdirect, content = "<?xml version="1.0" encoding="UTF-8"?><Worksheet><Group view='presentation' hide-input='false' hide-output='false' inline-output='false' drawlabel='true'><Input><Text-field alignment='left' style='Text' layout='Normal'><Font style='Hyperlink'><Hyperlink linktarget='https://learn.maplesoft.com/d/HJGLEUPKCKHGHQLKNIMJNSAMBUEKAQJNISCTMREHOPBPGNCPAHGSPNONEOPMLLNQLIBUMJOFMJLTGHKTCFBNCGFRHFNSOUDUCHNK' hyperlink='true'>https://learn.maplesoft.com/d/HJGLEUPKCKHGHQLKNIMJNSAMBUEKAQJNISCTMREHOPBPGNCPAHGSPNONEOPMLLNQLIBUMJOFMJLTGHKTCFBNCGFRHFNSOUDUCHNK</Hyperlink></Font></Text-field></Input></Group></Worksheet>", state = "", minimal = true
The DocumentTools[Canvas][Script] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
GetCanvas
Math
NewCanvas
ShowCanvas
Text
Download Help Document