- •3.1 What Lua Scripting?
- •3.2 Common Lua Command Set
- •3.3 Magnetics Preprocessor Lua Command Set
- •3.3.1 Object Add/Remove Commands
- •3.3.2 Geometry Selection Commands
- •3.3.3 Object Labeling Commands
- •3.3.4 Problem Commands
- •3.3.5 Mesh Commands
- •3.3.6 Editing Commands
- •3.3.7 Zoom Commands
- •3.3.8 View Commands
- •3.3.9 Object Properties
- •3.3.10 Miscellaneous
- •3.4 Magnetics Post Processor Command Set
- •3.4.1 Data Extraction Commands
- •3.4.2 Selection Commands
- •3.4.3 Zoom Commands
- •3.4.4 View Commands
- •3.4.5 Miscellaneous
Chapter 3
Lua Scripting
3.1 What Lua Scripting?
The Lua extension language has been used to add scripting/batch processing facilities to FEMM.
The Interactive Shell can run Lua scripts through the Open Lua Script selection on the Files menu, or Lua commands can be entered in directly to the Lua Console Window. Lua is a complete, open-source scripting language. Source code for Lua, in addition to detailed
documentation about programming in Lua, can be obtained from the Lua homepage at
http://www.lua.org. Because the scripting files are text, they can be edited with any text editor (e.g. notepad). As of this writing, the latest release of Lua is version 5.0. However, the version of Lua incorporated into FEMM is Lua 4.0.
In addition to the standard Lua command set described in [7], a number of FEMM-specific
functions have been added for manipulating files in both the pre- and post-processor. These commandsare described in the following sections.
3.2 Common Lua Command Set
A number of FEMM-specific Lua commands exist that are not associated with any particular problem
type.
• clearconsole() Clears the output window of the Lua console.
• create(doctype) Creates a new preprocessor document and opens up a new preprocessor
window. Specify doctype to be 0 for a magnetics problem or 1 for an electrostatics problem.
• hideconsole() Hides the floating Lua console window.
• hidepointprops() Hides the floating FEMM Properties display window.
• messagebox("message") displays the "message" string to the screen in a pop-up message
box.
• open("filename") Opens a document specified by filename.
65
• pause()Waits for the ok button to be pressed, a debug helper.
• print() This is standard Lua “print” command directed to the output of the Lua console
window. Any number of comma-separated items can be printed at once via the print command.
• prompt("message") This function allows a Lua script to prompt a user for input. When
this command is used, a dialog box pops up with the "message" string on the title bar of the
dialog box. The user can enter in a single line of input via the dialog box. prompt returns the
user’s input as a string. If a numerical value is desired, the syntax tonumber(prompt("message"))
can be used.
• quit() Close all documents and exit the the Interactive Shell at the end of the currently
executing Lua script.
• showconsole() Displays the floating Lua console window.
• showpointprops() Displays the floating FEMM Properties display window.
3.3 Magnetics Preprocessor Lua Command Set
A number of different commands are available in the preprocessor. Two naming conventions can
be used: one which separates words in the command names by underscores, and one that eliminates
the underscores.
3.3.1 Object Add/Remove Commands
• mi addnode(x,y) Add a new node at x,y
• mi addsegment(x1,y1,x2,y2) Add a new line segment from node closest to (x1,y1) to
node closest to (x2,y2)
• mi addblocklabel(x,y) Add a new block label at (x,y)
• mi addarc(x1,y1,x2,y2,angle,maxseg) Add a new arc segment from the nearest node
to (x1,y1) to the nearest node to (x2,y2) with angle ‘angle’ divided into ‘maxseg’ segments.
• mi deleteselected Delete all selected objects.
• mi deleteselectednodes Delete selected nodes.
• mi deleteselectedlabels Delete selected block labels.
• mi deleteselectedsegments Delete selected segments.
• mi deleteselectedarcsegments Delete selects arcs.
66
