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

12 次查看(过去 30 天)
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 个评论
dpb
dpb 2019-11-26
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 2020-4-10
Still have same problem, tried all proposed options. Have you got it to work? Any other possible workarounds to try?

请先登录,再进行评论。

回答(3 个)

Steven Lord
Steven Lord 2019-11-13
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 个评论
liang
liang 2019-11-14
I have already tried this and still got error:
Invalid double parameters array definition (not a valid string array).

请先登录,再进行评论。


James Tursa
James Tursa 2019-11-26
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 2020-4-20
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 个评论
Qi Wu
Qi Wu 2022-7-14
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 2022-7-14
编辑:Qi Wu 2022-7-14
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!

请先登录,再进行评论。

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by