CST Microwave Studio Macro - "Save" vba command problem
I'm having trouble saving a model programmatically that was built using a strucure macro. For example, I'll build the geometry in the macro, define the ports and materials in the macro, then issue the "save" or "saveas" commands in the macro and a file appears when I run it but when I open the file, it only has the geometry and a few other parts. The ports, field monitors and other components are missing. When I save the model that was built with the macro using the button in the GUI, it saves fine. When I save it using the command at the end of the macro, it doesn't save right.
Has anyone figured out a workaround? I'm trying to run CST in batch mode and build, run, and save the model and export results all using a macro.
Thank you in advance.
I think it is what you have in your history that matters. So if you save whatever that is in the history tree to your vba file you should get everything when you run the macro .
Element7k,
Thanks for responding.
Yeah, saving the commands in the history list is how I build the macro. When I run the macro, I also add a save command to the end of it but when it saves the model, it doesn't include everything. When I open the saved model, it's missing ports, field monitors, and other things.
When I press save in the GUI after the macro runs, then it saves fine but when I have the macro do the saving, the file doesn't save properly. I think when the macro finishes it returns control to the GUI and it refreshes it somehow so it saves right. The problem is that in my application, I'm trying to bypass all the GUI commands and just run a macro, save the model, and close the program without any user interaction.
Thanks again.
perhaps you can use this before save/saveAs command to update the history:
AddToHistory ( string header, string contents ) bool
The explanation of how to use the above is from the CST Website:
Adds a new entry to the history list entitled header. The contents of the entry is stored in contents. This contents is executed through the VBA interpreter if this method is called. Therefore it must contain valid VBA commands for CST MICROWAVE STUDIO. If the new entry could be created and the contents could be executed AddToHistory returns True, otherwise False.
e.g.
Dim DiscretePort As Object
e.g. AddToHistory ("Define Discrete Port ", DiscretePort)
Thanks for the feedback.
I tried updating the history list but it still wouldn't save correctly. I reverted to building the model in the GUI, saving it (using the gui), and then using the macro to open the file and modify the parameters. This worked really well and saved simulation time because I didn't have to rebuild the model every time I wanted to simulate a different geometry.