The Method Editor
Use the Method Editor to write custom code for tasks that go beyond the standard run commands available in the model tree nodes of the Model Builder. These methods can perform operations such as executing loops, processing inputs and outputs from various sources, and sending messages or alerts to the application user.
The Java® programming language is used to write COMSOL methods, which means that all Java® syntax and Java® libraries can be used. The Method Editor supports Java 11 syntax. In addition to the Java® libraries, the Application Builder has its own built-in library for building applications and modifying the model object. The model object is the data structure that stores the state of the underlying COMSOL Multiphysics model that is embedded in the application. More information about these built-in methods can be found in Appendix E — Built-In Method Library, in the Application Programming Guide, and in the Programming Reference Manual.
The contents of the application tree in the Application Builder are accessed through the application object, which is an important part of the model object. You can record and write code using the Method Editor that directly accesses and changes user interface aspects of the running application, such as button texts, icons, colors, and fonts.
There are global methods, form methods, and local methods. Global methods are displayed in the application tree and are accessible from all methods and form objects. Form methods are displayed in the application tree as child nodes to the form it belongs to. A local method is associated with a form object or event and can be opened from the corresponding Settings window. For more information about local methods, see Local Methods.
A number of tools and resources are available to help you create code for methods. These are covered in the following sections and will make you more productive by allowing you to copy-paste or autogenerate blocks of code, for example.