5

I'm trying to read some data from CST Microwave Studio in MATLAB using CST's COM objects.

First, I got the project COM object's reference by executing

hApp = actxserver(ProgID);
hProj = hApp.OpenFile(ProjectFile);

At this point normally COM server returns signatures of all available methods of the COM-object by executing

MethSig = invoke(hProj);

It works well in e.g. MS Office programs, but it returns nothing for CST COM-objects... (Is it something to do with IDispatch interface not implemented in CST?)

Anyway, it is possible to call CST COM-object's methods by using the following syntax (taking the MethodName and its arguments from the CST VBS documentation):

Out1 = hProj.invoke(MethodName, In1, In2, ...)

However, some methods return several output arguments, e.g. (again, from CST VBS documentation):

GetParameterCombination( string  resultID, variant parameterNames, variant  parameterValues  ) bool

where resultID is the input argument, and parameterNames and parameterValues are output arguments. In a such case in other COM-enabled apps (like MS Office) MATLAB takes care of the output parameters splitting, and the following syntax would work:

[Out1, Out2, ...] = hWorkSheet.invoke(MethodName, In1, In2, ...);
% or even using dot-notation:
[Out1, Out2, ...] = hWorkSheet.MethodName(In1, In2, ...);

However, it doesn't work with CST:

[RetVal, parameterNames, parameterValues] = hProj.invoke('GetParameterCombination', '3D:RunID:1');
Error using Interface.CSTStudio_Application.Active3D/invoke
Error: Missing a required parameter

I have tried to pass the output arguments in similar ways as in this question, without any success, always getting the error:

Error using Interface.CSTStudio_Application.Active3D/invoke
Error: Type mismatch, argument 2

Is there any way to get all output variables from a COM-object in this case? A some sort of Java wrapper perhaps?

Thanks.

Oleg
  • 111
  • 9
  • The question is still actual... Nobody has any idea? – Oleg Apr 23 '19 at 23:00
  • I don't know if that makes a difference but the signature for `GetParameterCombination` seems to have 3 parameters as input (even if 2 of them are also outputs). In your line `[RetVal, parameterNames, parameterValues] = hProj.invoke('GetParameterCombination', '3D:RunID:1');` shouldn't you send 2 more parameters ? Even if they won't actually hold the return values in Matlab, the COM server might need them to perform appropriately (also the error message `Missing a required parameter` seems to indicates it is expecting more inputs ...) – Hoki Apr 25 '19 at 11:10
  • @Hoki, Thanks for the comment. As I mentioned at the end of the question, I have tried to pass additional arguments (and also gave a link to the thread, where the author tried similar things), but I always get error `Error: Type mismatch, argument 2` ... – Oleg Apr 26 '19 at 08:00
  • Could you show the full line which produced this error ? (so we can see what type were the arguments sent in) – Hoki Apr 26 '19 at 11:37
  • 1
    also, could this Matlab toolbox help you : [A Matlab to CST Interface](https://uk.mathworks.com/matlabcentral/fileexchange/67731-hgiddenss-cst_app) ? – Hoki Apr 26 '19 at 11:48
  • @Hoki, I have tried several ways, e.g. 1) `[RetVal, parameterNames, parameterValues] = hProj.invoke('GetParameterCombination', '3D:RunID:1');`, 2) `parameterNames = {}; parameterValues = []; RetVal = hProj.invoke('GetParameterCombination', '3D:RunID:1', parameterNames, parameterValues);`, 3) `parameterNames = cell(0,0);`, 4) also using Matlab's `libpointer` as `parameterNames = libpointer('stringPtrPtr');` and other data types. All of these gives the same error `Error: Type mismatch, argument 2`... – Oleg May 03 '19 at 07:12
  • As for the Matlab to CST interface you refer to, yes, I saw it before, and it is a great peace of work, but the author doesn't use APIs with several output arguments, so it dosn't help with my problem... For now I use a work-around: from Matlab I write VBA macro which runs within CST and saves output data to a text file, which I then read in Matlab. But I'm still looking for a better solution... – Oleg May 03 '19 at 07:20

0 Answers0