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

22 vues (au cours des 30 derniers jours)
liang
liang le 13 Nov 2019
Modifié(e) : Qi Wu le 14 Juil 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 commentaires
dpb
dpb le 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 le 10 Avr 2020
Still have same problem, tried all proposed options. Have you got it to work? Any other possible workarounds to try?

Connectez-vous pour commenter.

Réponses (3)

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

Connectez-vous pour commenter.


James Tursa
James Tursa le 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 le 20 Avr 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 commentaires
Qi Wu
Qi Wu le 14 Juil 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 le 14 Juil 2022
Modifié(e) : Qi Wu le 14 Juil 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!

Connectez-vous pour commenter.

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by