ActiveX: how to pass a string array to cst in matlab?

5 views (last 30 days)
liang
liang on 13 Nov 2019
Edited: Qi Wu on 14 Jul 2022
hi, i'm using the activex interface to control cst(2019) by matlab(2018).matlab works fine as it comes to pass number and sting to cst.
However,when is comes to pass a string array, i get error:
Invalid double parameters array definition (not a valid string array).
I want to know how to pass a string array to cst in matlab.
the matlab code is:
oCSTApp = actxserver('CSTStudio.application');
oProject= oCSTApp.invoke('NewMWS');
Block = invoke(oProject,'Block');
Block.invoke('Reset')
Block.invoke('Type', 'MicrostripCoupledLinesIrregular')
Block.invoke('Name', 'MC2')
Block.invoke('SetIntegerProperty','Number Of Lines', 4)
sWidth={"0.5";"1.1";"2.2";"3.3"}
Block.invoke('SetDoubleArrayProperty','Widths', sWidth)(will get error here!)
the VBA code is :
'Create a block
With Block
.Reset
.Type ("MicrostripCoupledLinesIrregular")
.Name ("MC2")
Dim sWidth(0 To 3) As String
sWidth(0) = "0.5"
sWidth(1) = "1.1"
sWidth(2) = "2.2"
sWidth(3) = "3.3"
.SetIntegerProperty("Number Of Lines", 4)
.SetDoubleArrayProperty("Widths", sWidth)
.Position(51050, 51000)
.Create
End With
  6 Comments
dpb
dpb on 26 Nov 2019
I'd guess your only hope will be thru MEX and a C-style string (null terminated char() array)
What if you try a char() array that mimics such in MATLAB?
Johan
Johan on 10 Apr 2020
Still have same problem, tried all proposed options. Have you got it to work? Any other possible workarounds to try?

Sign in to comment.

Answers (3)

Steven Lord
Steven Lord on 13 Nov 2019
sWidth={"0.5";"1.1";"2.2";"3.3"}
The error message is accurate in that sWidth is not a string array. It is a cell array whose cells contain string arrays. You could try passing an actual string array, though I'm not certain exactly how string interacts with COM objects.
sWidth=["0.5";"1.1";"2.2";"3.3"]
  1 Comment
liang
liang on 14 Nov 2019
I have already tried this and still got error:
Invalid double parameters array definition (not a valid string array).

Sign in to comment.


James Tursa
James Tursa on 26 Nov 2019
Couple of things you might also try
sWidth={'0.5';'1.1';'2.2';'3.3'};
or
sWidth={'0.5';'1.1';'2.2';'3.3'};
sWidth = cellfun(@(x)[uint8(x) uint8(0)],sWidth,'uni',false);

Johan
Johan on 20 Apr 2020
Finally found a workaround that works, although not really a Matlab solution.
I dont think the Matlab and VBA string array variables are compatable, I have tried everything I could think of.
The solution is thus to write a VBA macro in CST. You can thus :
  1. Write the parameter data to a text file from Matlab.
  2. From Matlab, launch the CST macro by invoking the RunMacro command.
  3. From the CST macro, read the text file to get the required parameters, and do the rest in VBA.
I can confirm that this is +-10 times faster than writing individual strings from Matlab as well.
Good luck
  3 Comments
Qi Wu
Qi Wu on 14 Jul 2022
Thanks for your reply. I have the same problem and your solution seems the best way to solve the problem. But I have encountered a problem when trying your steps:
I have the text file of parameter data, but how can I write the macro to read the text file? How to let CST know that the text file is for parameter updating?
Thanks!!
Qi Wu
Qi Wu on 14 Jul 2022
Edited: Qi Wu on 14 Jul 2022
Now I have rewrite the txt into a bas file, and it can be successfully implemented if open it from CST, but I have trouble when trying to open it in Matlab using :
invoke(mws, 'RunMacro',tmpScriptFile);
Matlab will reture: Macro not found
Can you kindly tell me how to implement it from Matlab?
Thanks!

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!