DocumentTools/Canvas/Script/SetActive - Maple Help

DocumentTools[Canvas][Script]

 SetActive
 set which canvas element is active

 Calling Sequence SetActive(script,Id)

Parameters

 script - DocumentTools:-Canvas:-Script object Id - canvas element, string, or (group,row) pair

Description

 • The SetActive command specifies which component of a canvas is active.  Further script operations can operate relative to the active element, such as changing the math, or adding new components beside or below.
 • A "canvas" is an interactive section of a Maple document created by the NewCanvas command, or a shared web-based Maple Learn document.  See the Script command for a more complete description.
 • The Id argument can be an element containing an id, as per the returned elements from GetMath, or it can be the id itself as a string, or (group,row) pair.  The first math or text component on a canvas has the id "0:0".   The second math or text component measured left-right, then top-down on the canvas has the id "1:0" unless it is in the same group as the first, in which case it will have id "0:1".  Only elements of a group can have nonzero after the colon.
 • Be careful when using a literal id to reference an element from a canvas fetched by the GetCanvas command.  A Maple Learn document that a user has modified can have new groups anywhere and the id order may not match the template order of the components prior to insertion of those groups.  In these cases it is best to use the element returned by the GetMath command when applying scripts.

Examples

In this example, we will insert a canvas, get the math from the canvas, then make various elements active so that operations can be performed

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$

create a canvas with a title, two column headers, and two math expressions

 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Sample Canvas",\left["Column 1","Column 2"\right],\left[x,y\right]\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$
 > $\mathrm{sc}≔\mathrm{Script}\left(\right):$

get just the math, and note the id if the first element

 > $\mathrm{data}≔\mathrm{GetMath}\left(\right):$
 > $\mathrm{data}\left[1\right]:-\mathrm{id}$

By setting the first element active, we can perform operations relative to this expression, such as adding an annotation

 > $\mathrm{SetActive}\left(\mathrm{sc},\mathrm{data}\left[1\right]\right)$
 > $\mathrm{Annotate}\left(\mathrm{sc},"the first math element"\right)$
 > $\mathrm{SetActive}\left(\mathrm{sc},\mathrm{data}\left[2\right]\right)$
 > $\mathrm{Annotate}\left(\mathrm{sc},"the second math element"\right)$

Let's go back and extract all of the elements, including the text fields

 > $\mathrm{data}≔\mathrm{GetMath}\left('\mathrm{keeptext}'=\mathrm{true}\right):$

Note the id starts at "0:0"

 > $\mathrm{data}\left[1\right]:-\mathrm{id}$
 > $\mathrm{SetActive}\left(\mathrm{sc},\mathrm{data}\left[1\right]\right)$
 > $\mathrm{SetText}\left(\mathrm{sc},"Change the Title"\right)$
 > $\mathrm{SetActive}\left(\mathrm{sc},\mathrm{data}\left[-1\right]\right)$
 > $\mathrm{SetMath}\left(\mathrm{sc},z,\mathrm{where}="below"\right)$

Compatibility

 • The DocumentTools[Canvas][Script][SetActive] command was introduced in Maple 2021.