Making CST Files with Matlab
I'm trying to make a CST model from within matlab. Here's the code I have so far:
cst = actxserver('CSTStudio.application');mws = cst.invoke('NewMWS');brick=invoke(mws,'Brick');invoke(brick, 'Reset');invoke(brick, 'Name', 'brick1');invoke(brick, 'Component','component1');invoke(brick, 'Material', 'PEC');invoke(brick, 'Xrange', '0', '2');invoke(brick, 'Yrange', '0', '3');invoke(brick, 'Zrange', '0', '5');invoke(brick, 'Create');release(brick);mws.invoke('saveas','TEST.cst','false');
mws.invoke('rebuild')
Anyone knows why the history list isn't getting updated when using this interface?
@Firewall,
I'm considering pursuing a similar path with constructing my models in CST (through MATLAB). However I'm wondering if there are any documentation from CST or any other party that gives you a good idea about the process. I recall reading a thesis online once, where a student manipulates many of CST's methods using MATLAB but I can't seem to find it again.
Do you (or anyone reading this) have any material that might prove helpful ?
Bannay
I guess the short answer is no, I didn't really find anything useful, besides the CST documentation for VBA objects.
Most of what I figured out was from trial and error, and using the CST help files. This is basically what I think the process is:
1. With CST, you can make macros with VBA (some programming language that I'm not too familiar with).
2. Since CST is VBA-compatible, it can be accessed from other VBA-compatible programs (excel is a common example).
3. Matlab can also handle VBA-like commands, so you can use it to control CST.
CST's help files have a entire section about VBA 'objects' available for manipulation. (They also have a section specifically about using Matlab with CST, but that section only talks about getting results from CST, not making models for CST)
The CST help files give a detailed description of all the objects and their various settings. For example, if you look up the documentation for the 'Brick' object, it gives a list of a bunch of methods used to modify a brick. At the bottom, it gives an example of how to create a 'brick' object in VBA:
With Brick .Reset .Name ("brick1") .Component ("component1") .Material ("PEC") .Xrange (0, 2) .Yrange (0, 3) .Zrange (0, "a+3") .CreateEnd With
I've attached two files: one is the VBA code used to create a template for a planar filter (mm, GHz, ns, electric boundaries, etc). I grabbed it from the history list of a CST file that used the template.
The second file is the matlab version of the template. the 'mws' variable/object in this script is the same as the one in the original post:
cst = actxserver('CSTStudio.application');mws = cst.invoke('NewMWS');
So that's all I have to offer. I've still having the problems mentioned in the original post, though, and would gladly accept any new information anybody has to share.
Excellent Information @Firewall. Thank you.
I have now fought CST for long, and I also encountered this issue of a history-less brick creation. I found a work-around; although it is not pretty, the function AddToHistory does the job. You must create the component "MyBeautifulBrick" before this creation.
mws.invoke('AddToHistory', 'BricksyCreation',[... sprintf('With Brick\n') ... sprintf(' .Reset\n') ... sprintf(' .Name "Bricksy"\n') ... sprintf(' .Component "MyBeautifulBrick"\n') ... sprintf(' .Material "PEC"\n') ... sprintf(' .Xrange "%0.6f", "%0.6f"\n', -w/2, w/2) ... sprintf(' .Yrange "%0.6f", "%0.6f"\n', -h/2, h/2) ... sprintf(' .Zrange "%0.6f", "%0.6f"\n', -d/2, d/2) ... sprintf(' .Create\n') ... sprintf('End With')])