﻿# COMサーバーの使用

> [HTML Version](using-the-com-server.html)

COM サーバーを使用すると、他のプログラムから MESYS ソフトウェア内の関数を呼び出すことができます。

A simple example in a VisualBasic function:

````
Public Sub test()

Dim mesys As MesysCOM

Set mesys = New MesysCOM

Dim rbc As MesysRBC



Set rbc = mesys.createRBC

Dim d As Long

Dim pmax As Double



Call rbc.setVarInt("inputType", 2)

Call rbc.setVarInt("Z", 12)

Call rbc.setVarDouble("Dw", 5)

Call rbc.setVarDouble("Dpw", 50)

Call rbc.setVarDouble("Fy", 1000)

Call rbc.setVarDouble("ni", 500)



result = rbc.Calculate

Call rbc.showReport("c:/temp/report.pdf")

Call rbc.getVarDouble("pmax", pmax)

Call rbc.getVarInt("Z", d)

Call rbc.calculateBearing(True, 0, True, 1000, True, 0, False, 0, False, 0, 500, 0, 20, 20)

Call rbc.getVarDouble("pmax", pmax)

Set rbc = Nothing

Set mesys = Nothing



End Sub



````
And here the same example in Python using the members with variants as \[in, out\] parameters do not work from python:

````
import comtypes.client



mesys = comtypes.client.CreateObject("MesysCOM64.MesysCOM")

rbc = mesys.createRBC()

rbc.setVar("inputType", 2)

rbc.setVar("Z", 12)

rbc.setVar("Dw", 5)

rbc.setVar("Dpw", 50)

rbc.setVar("Fy", 1000)

rbc.setVar("ni", 500)

rbc.calculate()

rbc.showReport("c:/temp/report.pdf")

pmax = rbc.getVar("pmax")

z = rbc.getVar("Z")

rbc.calculateBearing(True, 0, True, 1000, True, 0, False, 0, False, 0, 500, 0, 20, 20)

pmax2 = rbc.getVar("pmax")

stiffness = rbc.getStiffnessMatrixAsVector();

rbc = None

mesys = None

````
 

The server provides the interface MesysCOM which can be used to create calculation modules. Available methods are:

- void setLanguage(\[in\] BSTR p\_lang);  
Pass language as two characters ("de", "en", "fr", "es", "tr", "ko", "zh", "ja")

- int getVersion();  
Returns version in format yyyymm.

- MesysRBC\* createRBC();  
Create bearing calculation module without user interface.

- MesysSHAFT\* createSHAFT();  
Create shaft calculation module without user interface.

- MesysHERTZ\* createHERTZ();  
Create Hertz stress calculation module without user interface.

- MesysBALLSCREW\* createBALLSCREW();  
Create ball screw calculation module without user interface.

- MesysGUIRBC\* createGUIRBC();  
Create bearing calculation module with user interface.

- MesysGUIHERTZ\* createGUIHERTZ();  
Create hertz stress calculation module with user interface.

- MesysGUISHAFT\* createGUISHAFT();  
Create shaft calculation module with user interface.

- MesysGUIBALLSCREW\* createGUIBALLSCREW();  
Create ball screw calculation module with user interface.



The interfaces MesysRBC, MesysSHAFT and others without GUI create calculation modules without user interface. MesysGUIRBC, MesysGUISHAFT are calculation modules with user interface.

General methods for all calculation modules are:

- VARIANT\_BOOL calculate();  
Run calculation.

- VARIANT\_BOOL loadFile(\[in\] BSTR p\_filename);  
Load file.

- VARIANT\_BOOL saveFile(\[in\] BSTR p\_filename);  
Save calculation file.

- VARIANT\_BOOL generateReport(\[in\] BSTR p\_filename);  
Generate a report into the filename.

- VARIANT\_BOOL showReport(\[in\] BSTR p\_filename);  
Generate the report into the filename and call a program to view it.

- VARIANT\_BOOL generateSpecialReport(\[in\] BSTR p\_type, \[in\] BSTR p\_filename);

- Generate a special report into the filename. Use type as "resultTables" for result tables.

- VARIANT\_BOOL generateImage(\[in\] BSTR p\_imageID, \[in\] BSTR p\_filename, \[in\] int p\_dpi, \[in\] int p\_widthinMM, \[in\] int p\_heightinMM);  
Generate an image and save it as file.

- SAFEARRAY(VARIANT) getDiagramData(\[in\] BSTR p\_imageID);  
Get the diagram data for diagrams. The format of the return value is \[\["name", \["x", "abscissa label", "abscissa unit", \[1, 2, 3, ...\], \["y", "ordinate label", "ordinate unit", \[1, 2, 3, ...\]\], \["name", ...\]\]

- VARIANT\_BOOL setVarDouble(\[in\] BSTR p\_name, \[in\] double p\_value);  
Set variable to double value.

- VARIANT\_BOOL setVarBool(\[in\] BSTR p\_name, \[in\] VARIANT\_BOOL p\_value);  
Set variable to boolean value.

- VARIANT\_BOOL setVarInt(\[in\] BSTR p\_name, \[in\] int p\_value);  
Set variable to integer value.

- VARIANT\_BOOL setVarString(\[in\] BSTR p\_name, \[in\] BSTR p\_value);  
Set variable to character value.

- VARIANT\_BOOL getVarDouble(\[in\] BSTR p\_name, \[in,out\] double \*p\_value);  
Read back double variable.

- VARIANT\_BOOL getVarBool(\[in\] BSTR p\_name, \[in,out\] VARIANT\_BOOL \*p\_value);  
Read back boolean variable.

- VARIANT\_BOOL getVarInt(\[in\] BSTR p\_name, \[in,out\] int \*p\_value);  
Read back integer variable.

- VARIANT\_BOOL getVarString(\[in\] BSTR p\_name, \[in,out\] BSTR \*p\_value);  
Read back character variable.

- VARIANT\_BOOL setVar(\[in\] BSTR p\_name, \[in\] VARIANT p\_value);  
Set variable using variant

- VARIANT getVar(\[in\] BSTR p\_name);  
Get variable using variant

- VARIANT\_BOOL resizeArray(\[in\] BSTR p\_name, \[in\] int p\_count);  
Resize array variable





Additional methods for bearing calculation:



- VARIANT\_BOOL calculateBearing(\[in\] VARIANT\_BOOL p\_enterFx, \[in\] double p\_Fx\_or\_Ux, \[in\] VARIANT\_BOOL p\_enterFy, \[in\] double p\_Fy\_or\_Uy, \[in\] VARIANT\_BOOL p\_enterFz, \[in\] double p\_Fz\_or\_Uz, \[in\] VARIANT\_BOOL p\_enterMy, \[in\] double p\_My\_or\_Ry, \[in\] VARIANT\_BOOL p\_enterMz, \[in\] double p\_Mz\_or\_Rz, \[in\] double p\_ni, \[in\] double p\_ne, \[in\] double p\_Ti, \[in\] double p\_Te);  
Run bearing calculation with given loading.

- VARIANT\_BOOL setupLoadSpectrum(\[in\] int p\_count, \[in\] VARIANT\_BOOL p\_enterFx, \[in\] VARIANT\_BOOL p\_enterFy, \[in\] VARIANT\_BOOL p\_enterFz, \[in\] VARIANT\_BOOL p\_enterMy, \[in\] VARIANT\_BOOL p\_enterMz);  
Setup load spectrum definition.

- VARIANT\_BOOL setLoadSpectrumLoad(\[in\] int p\_loadCase, \[in\] double p\_frequency, \[in\] double p\_Fx\_or\_Ux, \[in\] double p\_Fy\_or\_Uy, \[in\] double p\_Fz\_or\_Uz, \[in\] double p\_My\_or\_Ry, \[in\] double p\_Mz\_or\_Rz, \[in\] double p\_ni, \[in\] double p\_ne, \[in\] double p\_Ti, \[in\] double p\_Te, \[in\] double p\_TOil);  
Set load spectrum load for each load case

- VARIANT\_BOOL selectBearingFromDatabase(\[in\] BSTR p\_manufacturer, \[in\] BSTR p\_bearingName);  
Selects a bearing based on name and manufacturer from the database

- VARIANT\_BOOL getStiffnessMatrix(\[in,out\] double \*p\_c11, \[in,out\] double \*p\_c12, \[in,out\] double \*p\_c13, \[in,out\] double \*p\_c14, \[in,out\] double \*p\_c15, \[in,out\] double \*p\_c21, \[in,out\] double \*p\_c22, \[in,out\] double \*p\_c23, \[in,out\] double \*p\_c24, \[in,out\] double \*p\_c25, \[in,out\] double \*p\_c31, \[in,out\] double \*p\_c32, \[in,out\] double \*p\_c33, \[in,out\] double \*p\_c34, \[in,out\] double \*p\_c35, \[in,out\] double \*p\_c41, \[in,out\] double \*p\_c42, \[in,out\] double \*p\_c43, \[in,out\] double \*p\_c44, \[in,out\] double \*p\_c45, \[in,out\] double \*p\_c51, \[in,out\] double \*p\_c52, \[in,out\] double \*p\_c53, \[in,out\] double \*p\_c54, \[in,out\] double \*p\_c55);  
Reads back the bearing stiffness matrix with units N, Nm, mm, rad. The order of rows and columns is like in the report ux, uy, uz, ry, rz.

- SAFEARRAY(VARIANT) getStiffnessMatrixAsVector();  
Reads back the bearing stiffness matrix  as vector with units N, Nm, mm, rad. The order of the elements is per row.

- SAFEARRAY(VARIANT) getRollingElementResults(\[in\] int p\_loadCase, \[in\] int p\_bearing, \[in\] int p\_row, \[in\] int p\_rollingElement, \[in\] int p\_section);  
Returns results for single rolling elements. The parameter 'section' is only used for roller bearings, for section==-1 the forces acting on the roller are returned. The parameter 'loadCase' is only used if a load spectrum is defined.



Additional methods for ball screw calculation:



- VARIANT\_BOOL calculateBallScrew(\[in\] VARIANT\_BOOL p\_enterFx, \[in\] double p\_Fx\_or\_Ux, \[in\] VARIANT\_BOOL p\_enterFy, \[in\] double p\_Fy\_or\_Uy, \[in\] VARIANT\_BOOL p\_enterFz, \[in\] double p\_Fz\_or\_Uz, \[in\] double p\_Rx, \[in\] VARIANT\_BOOL p\_enterMy, \[in\] double p\_My\_or\_Ry, \[in\] VARIANT\_BOOL p\_enterMz, \[in\] double p\_Mz\_or\_Rz, \[in\] double p\_ni, \[in\] double p\_ne, \[in\] double p\_Ti, \[in\] double p\_Te);  
Run ball screw calculation with given loading

- VARIANT\_BOOL setupLoadSpectrum(\[in\] int p\_count, \[in\] VARIANT\_BOOL p\_enterFx, \[in\] VARIANT\_BOOL p\_enterFy, \[in\] VARIANT\_BOOL p\_enterFz, \[in\] VARIANT\_BOOL p\_enterMy, \[in\] VARIANT\_BOOL p\_enterMz);  
Setup load spectrum definition

- VARIANT\_BOOL setLoadSpectrumLoad(\[in\] int p\_loadCase, \[in\] double p\_frequency, \[in\] double p\_Fx\_or\_Ux, \[in\] double p\_Fy\_or\_Uy, \[in\] double p\_Fz\_or\_Uz, \[in\] double p\_Rx, \[in\] double p\_My\_or\_Ry, \[in\] double p\_Mz\_or\_Rz, \[in\] double p\_ni, \[in\] double p\_ne, \[in\] double p\_Ti, \[in\] double p\_Te);  
Sets load spectrum load for each load case

- VARIANT\_BOOL getStiffnessMatrix(\[in,out\] double \*p\_c11, \[in,out\] double \*p\_c12, \[in,out\] double \*p\_c13, \[in,out\] double \*p\_c14, \[in,out\] double \*p\_c15, \[in,out\] double \*p\_c21, \[in,out\] double \*p\_c22, \[in,out\] double \*p\_c23, \[in,out\] double \*p\_c24, \[in,out\] double \*p\_c25, \[in,out\] double \*p\_c31, \[in,out\] double \*p\_c32, \[in,out\] double \*p\_c33, \[in,out\] double \*p\_c34, \[in,out\] double \*p\_c35, \[in,out\] double \*p\_c41, \[in,out\] double \*p\_c42, \[in,out\] double \*p\_c43, \[in,out\] double \*p\_c44, \[in,out\] double \*p\_c45, \[in,out\] double \*p\_c51, \[in,out\] double \*p\_c52, \[in,out\] double \*p\_c53, \[in,out\] double \*p\_c54, \[in,out\] double \*p\_c55);  
Reads back the stiffness matrix with units N, Nm, mm, rad. The order of rows and columns is like in the report ux, uy, uz, ry, rz.

- SAFEARRAY(VARIANT) getStiffnessMatrixAsVector();  
Reads back the bearing stiffness matrix  as vector with units N, Nm, mm, rad. The order of the elements is per row.

- SAFEARRAY(VARIANT) getRollingElementResults(\[in\] int p\_loadCase, \[in\] int p\_bearing, \[in\] int p\_thread, \[in\] int p\_rollingElement);  
Returns results for single rolling elements. The parameter 'loadCase' is only used if a load spectrum is defined and should be set to zero otherwise.



Additional methods for the shaft calculation:

- VARIANT\_BOOL importREXS(\[in\] BSTR p\_path);  
Import system in REXS format

- VARIANT\_BOOL exportREXS(\[in\] BSTR p\_path);  
Export system in REXS format

- void resizeLoadSpectrum(\[in\] int p\_count);  
Resize load spectrum, which needs to be active.

- VARIANT\_BOOL setLoadSpectrumElement(\[in\] int p\_id, \[in\] BSTR p\_component, \[in\] int p\_index, \[in\] double p\_value);  
Set data for load spectrum element

- VARIANT\_BOOL setPosition(\[in\] int p\_id, \[in\] double p\_position);  
Set position for force or support

- SAFEARRAY(VARIANT) getShaftIds();  
Get list of shaft IDs

- SAFEARRAY(VARIANT) getForceIds();  
Get list of force IDs

- SAFEARRAY(VARIANT) getSupportIds();  
Get list of support IDs

- SAFEARRAY(VARIANT) getSectionIds();  
Get list of section IDs

- SAFEARRAY(VARIANT) getBearingIds();  
Get list of bearing IDs

- SAFEARRAY(VARIANT) getBallscrewIds();  
Get list of ballscrew IDs

- SAFEARRAY(VARIANT) getGroupIds();  
Get list of group IDs

- SAFEARRAY(VARIANT) getElasticPartIds();  
Get list of elastic part IDs

- int getShaftIdByName(\[in\] BSTR p\_name);  
Get ID for first shaft with given name. Returns zero if not found.

- int getForceIdByName(\[in\] BSTR p\_name);  
Get ID for first force with given name. Returns zero if not found.

- int getSupportIdByName(\[in\] BSTR p\_name);  
Get ID for first support with given name. Returns zero if not found.

- int getSectionIdByName(\[in\] BSTR p\_name);  
Get ID for first section with given name. Returns zero if not found.

- int getBearingIdByName(\[in\] BSTR p\_name);  
Get ID for first bearing with given name. Returns zero if not found.

- int getBallscrewIdByName(\[in\] BSTR p\_name);  
Get ID for first ballscrew with given name. Returns zero if not found.

- int getElasticPartIdByName(\[in\] BSTR p\_name);  
Get ID for first elastic part with given name. Returns zero if not found.

- BSTR getName(\[in\] int p\_id);  
Get element name for ID

- VARIANT getIDVar(\[in\] int p\_id, \[in\] BSTR p\_name);  
Get variable for element with given ID

- VARIANT\_BOOL setIDVar(\[in\] int p\_id, \[in\] BSTR p\_name, \[in\] VARIANT p\_value);  
Set variable for element with given ID

- VARIANT\_BOOL resizeIDArray(\[in\] int p\_id, \[in\] BSTR p\_name, \[in\] int p\_count);  
Resize array variable for element with given ID

- MesysRBC\* getBearingModule(\[in\] int p\_id);  
Get bearing calculation for given ID as copy

- VARIANT\_BOOL setBearingModule(\[in\] int p\_id, \[in\] MesysRBC\* p1);  
Set bearing calculation for given ID

- MesysBALLSCREW\* getBallScrewModule(\[in\] int p\_id);  
Get ballscrew calculation for given ID as copy

- VARIANT\_BOOL setBallScrewModule(\[in\] int p\_id, \[in\] MesysBALLSCREW\* p1);  
Set ballscrew calculation for given ID  


Each calculation module with GUI provides following methods:

- void showWindow();  
Show user interface.

- void hideWindow();  
Hide user interface.

- void exec();  
Show user interface and process events until the window is closed.

- void setLanguage(\[in\] BSTR p\_lang);  
Pass language as two characters ("de", "en", "fr", "es", "tr", "ko", "zh", "ja")

- MesysModule\* getCalcModule();  
Get the calculation module from the user interface.

- void setCalcModule(MesysModule\*);  
Set the calculation module for the user interface.

- void runParameterVariation(\[in\] BSTR p\_resultFilePath);  
Runs the parameter calculation with the given definitions and saves the results table into the given file. Only available for shaft, bearing and ball screw calculation.



The names for variables of the calculation modules are the same as provided for the [custom report templates](custom-report-templates.md). Currently the use for the shaft calculation is limited as additional functions for changing loads and supports are missing.

