|
Calling Sequence
|
|
Script()
Script(s, options)
|
|
Parameters
|
|
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
|
|
|
|
|
Description
|
|
•
|
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.
|
|
|
List of Script Methods
|
|
|
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
|
set the contents of a math canvas element
|
SetState
|
annotate math
|
SetText
|
set the contents of a text canvas element
|
ToString
|
convert a script object to a XML string
|
|
|
|
|
Examples
|
|
|
Static Content in a Canvas
|
|
•
|
In this section we create a canvas with text, and math in columns.
|
>
|
|
>
|
|
|
|
Script to Populate a Canvas
|
|
•
|
In this section we create a blank canvas, then add text, and math via script commands.
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
•
|
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.
|
>
|
|
|
|
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:
|
>
|
|
|
|
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:
|
>
|
|
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
| |
|
|
|
Compatibility
|
|
•
|
The DocumentTools[Canvas][Script] command was introduced in Maple 2021.
|
|
|
|