In the Application Builder, custom code is represented by a Method node. To be able to write code, you must first create a
Method node. To create a
Method node, click the
New Method button (

) in the
Method ribbon toolbar, or right-click the
Methods node (

) in the
Application Builder window and select
New Method.
The new Method node appears under the
Methods node in the
Application Builder tree. It is also possible to create
local methods in some of the form objects in a form. These local methods connect to events in the form objects, such as when the setting (data) changes for a check box. The
Method node is used for referring to the method from a command sequence or a form object’s event.
A Method node contains COMSOL code and Java
® code, which you can inspect and edit by double-clicking it in the Application Builder window or by right-clicking and selecting
Edit. When a method is opened, it appears in a method editor window.
The code defines an ApplicationMethod Java class. This class has a method called
execute that the Command Sequence calls when the application runs it. A typical use case is that you create a
Method node, write some code in the
execute method, and link this code to a Command Sequence that a form object in the application’s user interface can trigger. Methods that affect the state of form objects apply immediately.
The default setting is to only display the code contained inside the execute method. To display all code, enable the
View all code check box, which is a preference setting in the
Methods section of the
Preferences dialog box.
When the execute method is triggered while running the application,
model is the
model object of the application. From it, you can access, for example, features of the physics and change their parameters.