AXISVM supports Microsoft COM technology allowing other programs to interact with it. Any program can launch AXISVM, build models, run calculations and get the analysis results through the COM server. Several Programming languages can be used to control AXISVM through the COM server, such as C#, Python, Delphi or even Excel using Excel VBA. This article will show the required steps to configure the AXISVM COM server and interact with AXISVM software. Visual Studio and C# are used in this article, but similar procedures can be followed in the case of other programming languages and IDEs.
Registration #
The COM server must be registered in the registry of the operating system to allow the IDEs (e.g., Visual Studio, Delphi IDE, Visual Basic Editor in Excel, and others) to see the AXISVM type library. The COM server is registered automatically during the installation of AXISVM. The IDE will show all the registered versions of the COM server.
Starting AXISVM through the COM server #
Here, Visual Studio 2022 and C# programming language are used to create a project and establish a connection to AXISVM through the COM server. The project will be a Windows Form App with a single button to run AXISVM.
Adding the COM server library to Visual Studio. #
- create a new project Windows Form App.
- right-click on the project name (here: AxisVMTutorial) in the solution explorer, and from Add menu, choose COM Reference. The reference manager window will appear, and in the search bar, type AXISVM. Check the checkbox next to AXISVM Library and click OK, as shown in the screenshots below. If there is more than one version of AxisVM, more than one AXISVM library will appear. The AXISVM library would appear in the project Dependencies if it were added successfully to the project.
- set the Embed Interop Types to No for Interop.AxisVM
Defining the logic to start the COM server #
The OpenAxisVM method shown below is used to define the required steps to start AXISVM. The description of each line code is written next to it. In general, the following steps must be followed:
- Define a global instance of the IAxisVMApplication interface and initialize it with an object of AxisVMApplication.
- Keep checking if AXISVM is loaded using the Loaded property of the AxisVMApplication object.
- Make AXISVM visible using the Visible property of the AxisVMApplication object.
- Right-click on the project name (here: AxisVMTutorial) in the solution explorer, and from Add menu, choose COM Reference. The reference manager window will appear, and in the search bar, type AXISVM. Check the checkbox next to AXISVM Library and click OK, as shown in the screenshots below. If there is more than one version of AXISVM, more than one AXISVM library will appear. The AXISVM library would appear in the project Dependencies if it were added successfully to the project.
IAxisVMApplication axisVMApplication; // Define a global variable for AxisVM.
public int OpenAxisVM(int _MaxWaitTime) // _MaxWaitTime in seconds.
{ const int cSleepTime = 100; // In milliseconds
int axisVMStatus=0; // Variable to track the status of AxisVM.
uint openTrialTimes = 0; // Number of times the program is trying to launch AxisVM.
if (this.axisVMApplication == null) // check if axisVMApplication is not defined.
{
this.axisVMApplication = new AxisVMApplication(); //Create an object of AxisVMApplication.
// Check the status of AxisVM (loaded or not) and the openTrialTimes is less than the maximum trial times.
while (((IAxisVMApplication)this.axisVMApplication).Loaded == ELongBoolean.lbFalse && (openTrialTimes < _MaxWaitTime * 1000 / cSleepTime))
{
System.Threading.Thread.Sleep(cSleepTime); // Put the thread to sleep.
openTrialTimes++; // Increase the number of trial times after each trial.
}
// check if the AxisVM is loaded and assign.
if (((IAxisVMApplication)this.axisVMApplication).Loaded == ELongBoolean.lbTrue)
{
axisVMStatus = 1; // Assign a value of 1 if loaded.
}
else
{
axisVMStatus = -1; // Assign -1 if not loaded.
}
// Check if the status is larger than 1 (i.e. loaded).
if (axisVMStatus > 0)
{
this.axisVMApplication.Visible = ELongBoolean.lbTrue; // Make AxisVM Visible.
}
else
{
this.axisVMApplication = null; // Assign null for the object.
}
return axisVMStatus; // Return the status of AxisVM.
}
return -1; // Return -1 if there is an defined object.
}
- Call the OpenAxisVM method in the project in the required place; as an example here, it is called in the button1_Click method that will be executed when the user clicks on the button, as shown in the figure below.
private void button1_Click(object sender, EventArgs e)
{
OpenAxisVM(100); // Execute the OpenAxisVM method.
}
- Run the Project from Debug menu and start debugging or using the F5 key. The Form with the added button will appear. Click on button 1 to start AXISVM.
- To Close AXISVM, the method Quit() of AxisVMApplication object must be called.
Common Problems #
- Several versions of the COM server are available on the operating system causing failure to connect to AXISVM.
Solution: Close Visual Studio and any running instance of AXISVM. Run UnregComServer.exe as administrator, which is available in the AXISVM installation directory. This will remove the previously registered COM servers. Register the COM server for the required version again by running as administrator !REGISTER_AXISVM.bat or !REGISTER_AXISVM_X64.bat for 32bit or 64bit, respectively. If the problem is not solved, reinstall AXISVM.
For further information, please refer to AXISVM COM Server Interface.