LabelMover Programming Overview
Starting from version 2.1 it is possible to control LabelMover operations programmatically.
This opens wide range of possible applications, including
- Custom modifications of QuickField models
You can use LabelMover programming interface to perform the individual changes of prepared QuickField model or to generate the sequence of problems.
Please pay attention: for technical reasons, you should ensure that LabelMover is in Optimization analysis mode to use the programming interface. However, the applications are not limited by optimization purposes only, you can use the programming interface for generation of any problems sequence.
- Using finite-element models as "black boxes" for optimization algorithms, control systems or system level simulation
In addition to using "raw" ActiveField with direct access to most of QuickField objects, programming interface to LabelMover gives the possibility of using the field models on more abstract level, without finite element specifics.
Exact field model may be controlled by few parameters, which may be used for programming your own optimization algorithms, interfacing with existing optimization software (for example, MATLAB, Excel etc.), integration of FEA models of the components into the system level simulation system, and variety of other applications.
And all these tasks require no knowledge about QuickField object model, you may use just few functions of the LabelMover programming interface.
Two kinds of programming interfaces to LabelMover are supported: COM interface and command line interface.
COM Interface
Functions
- SetVariation(index as Integer, value as Double)
Set value for the variation with the specified index.
Variations are indexed in the order as you see it at the Variations page of the LabelMover. Indexes start from 0.
Remark: If variation is described in LabelMover as Displacement in any direction, then it is necessary to specify two numbers in programming interface - one for X offset and another for Y offset. If variation is described as Displacement in fixed direction, then programmer should specify the X offset, except the case the displacement is in Y direction. In this case programmer should specify the Y offset.
- Solve()
LabelMover generates and solves new problem with the specified variations. (So, you should call SetVariation several times to specify variation before calling Solve()). Results are added to the table of results.
- GetResult(index as Integer) as Double
Return result value with the specified index.
Values are indexed in the order as you see it at the Values table of the LabelMover. Indexes start from 0.
Function returns results of the last problem being soved. So, you should call Solve() at least once before calling GetResult().
- ClearResults()
Remove all results from the result table. It is recommended to call ClearResults() at the beginning of your program.
Typical sequence of operations when working with LabelMover COM interface is the following:
- Call ClearResults()
- Generate and solve a sequence of problems. To generate each problem:
- Call SetVariation for each variation
- Call Solve()
- Call GetResultif you need some results to calculate next variations etc. (If you just want to show results in the table, then it is net necessary to call GetResult. All results will be added to the table of results automatically).
Example
Let us consider a very simple example. Suppose we have some QuickField problem and suppose we specified several parameters (variations) and several results for it using LabelMover.
We would like to set values 0.0, 0.1, 0.2 … 0.9 to one parameter, set values 0.0, 0.01, 0.02 … 0.09 to another parameter and get table of all possible combinations. (That is, we would like to generate 100 variants of the problem).
This is an example that does it in Visual Basic 2005:
Sub Main()
Dim qlm As QLM.SimpleInterface
qlm = CreateObject("QLM.SimpleInterface")
qlm.ClearResults()
Dim i, j As Integer
For i = 0 To 10
For j = 0 To 10
qlm.SetVariation(0, i * 0.1)
qlm.SetVariation(1, j * 0.01)
qlm.Solve()
Next
Next
End Sub
Remark:To use this code you should manually start LabelMover and ensure that it is in Optimization analysis mode and that at least two variations are specified.
Command Line Interface
You can use command line interface if you use programming language or environment that does not support COM. Also, even for programming languages that support COM, using the command line interface could be easier.
All you should know is how to execute external program (EXE file) with command line parameters in your program.
There is a special program QLMCall.exe in the LabelMover installation. To control LabelMover you just should execute QLMCall.exe with variation values (or additional commands) as parameters.
Command Line Parameters
- QLMCall variation0 variation1 ... variationN
[ ><output_file> ]
Generate new problem with specified variations, solve it and add results to the table of results.
Results are written to the specified output file, in text format as a sequence of numbers separated by spaces.
Parameter ><output_file> can be omitted. In this case results will be written to console.
Remark: For Displacement in any direction programmer should specify two numbers: X offset and Y offset. For displacement in fixed direction programmer should specify the X offset, except the case the displacement is in Y direction. In this case programmer should specify the Y offset.
- QLMCall ClearResults
Clear all results in the LabelMover result table.
Example
Les us rewrite the simple example described above using the command line interface:
Sub Main()
Dim i, j As Integer
Dim commandLine As String
Shell("QLMCall ClearResults", , True)
For i = 0 To 10
For j = 0 To 10
commandLine = "QLMCall " + _
Str(i * 0.1) + " " + Str(j * 0.01)
Shell(commandLine, , True)
Next
Next
End Sub
How to specify a path to QLMCall.exe
To work properly, Shell function should find QLMCàll.exe at disk. There are several ways to ensure it will be found:
- You can add the folder that contains QLMCàll.exe to the global environment variable Path.
(The folder in question is a "Tools\Label Mover" subfolder in the QuickField installation. For example, if QuickField is installed at disk C: then typically QLMCall.exe is in folder "C:\Program Files\Tera Analysis\QuickField 5.6\Tools\Label Mover".)
- Another way, you can just copy QLMCàll.exe to your current folder. (Its size is around 30K, so it is not a problem to create multiple copies).
- Another way, you can specify full path in the command line. In our simple example you can write:
commandLine = """C:\Program Files\Tera Analysis\" + _
"QuickField 5.6\Tools\Label Mover QLMCall"" " + _
Str(i * 0.1) + " " + Str(j * 0.01)
Please pay attention: you should put program name in additional quotes if the full path name contains spaces.
See also
Welcome to LabelMover