ActiveX: how to pass a string array to cst in matlab?
12 views (last 30 days)
Show older comments
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
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?
Answers (3)
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"]
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);
0 Comments
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 :
- Write the parameter data to a text file from Matlab.
- From Matlab, launch the CST macro by invoking the RunMacro command.
- 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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!