[python-win32] To control commercial software CST through python
Max Landaeus
max at landaeus.com
Fri Apr 28 07:17:42 EDT 2017
Hi,
I wrote some code to control CST a couple of years ago. It was quite
difficult to interface via COM, since some commands simply refused to
work. What I did in the end was to as few com-calls as possible and did
the rest in VB. Even if VB is a terrible language the end result was
more stable.
Among other things I wrote code to remotely create matching networks in
the Schematics (DS canvas). Then I created a class in Python to generate
VB code on the fly, saved it as a VB-file and used the
DS.RunScript(path) command to get CST to generate the network. This
worked well.
One more thing: I found that I had to use the DS._FlagAsMethod before I
used the actual command. I.e I had to do:
DS._FlagAsMethod("RunScript")
DS.RunScript(script_file_name)
That helped to get many commands to work - but not all.
BR,
Max
On 2017-04-24 21:12, gowri shankar wrote:
> Dear all,
> I want to control a commercial numerical solver CST
> through python. Usually, CST can be controlled using MATLAB. CST
> accepts both COM and VBA macros from MATLAB. As VBA is difficult and
> time consuming to program, i was successful in connecting the CST
> through COM interface from MATLAB. The sample snapshot of the commands
> are as below:
> ***********************************************************************
> / cst = actxserver('CSTStudio.application') % to open the CST/
> /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst'); %to open a
> particular file/
> / a=20;/
> / b=20;/
> / c=72;/
> / %To store the parameters/
> / mws.invoke('StoreParameter','a',a); %These are the COM interface
> commands from MATLAB to CST/
> / mws.invoke('StoreParameter','b',b);/
> / mws.invoke('StoreParameter','c',c);/
> / %To rebuild /
> / invoke(mws,'Rebuild');/
> /
> /
> / %%Setting only the required boudnary conditions only/
> / bound=invoke(mws,'Boundary'); %These are the COM interface
> commands from MATLAB to CST/
> / bound.invoke('Zmin','magnetic');/
> / bound.invoke('Zmax','magnetic');/
> /
> /
> / %% Set the frequency range/
> / solver=invoke(mws,'Solver');/
> / invoke(solver,'FrequencyRange',freMin,freMax);/
> /
> /
> / Esolver=invoke(mws,'EigenmodeSolver');/
> / invoke(Esolver,'Reset');/
> / invoke(Esolver,'SetMeshType','Tetrahedral Mesh');
> /
> / invoke(Esolver,'SetNumberOfModes',noOfMode);/
> / invoke(Esolver,'Start'); %Run the solver
> /
> /noOfModesCalculated=invoke(Esolver,'GetNumberOfModesCalculated');/
> / for j=1:noOfModesCalculated/
> /eigenFreq(j)=invoke(Esolver,'GetModeFrequencyInHz',j);/
> / end/
> /
> /
> / invoke(mws,'Save'); %Save the file/
> / invoke(mws, 'Quit'); %closes the file/
> / release(mws); /
> / invoke(cst, 'Quit'); % closes the CST application/
> / release(cst);/
> / dos(['taskkill /F /IM ' '"CST DESIGN ENVIRONMENT.exe"']);/
>
> **************************************************************************
> MATLAB commands work perfectly wihtout any fuss.
> *I have translated the above code in python but i was able to talk to
> CST with only first 2-3 commands i.e*
> *********************************
> /import win32com.client/
> /cst = win32com.client.Dispatch("CSTStudio.Application")/
> /#Opens a new CST file/
> /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');/
> /
> /
> /#mws=cst.NewMWS()/
> /
> /
> /###*Below this commands i got error or sometimes it didn't give any
> error but just it didn't worked*/
> /mws.StoreParameter('len2',10.1)/
> /mwssolver=mws.Solver()/
> /mws.Solver.Start()/
> *******************************
> I tried different online forums for help and i was unsuccessful in
> getting any clue how to move forward. Erros messages didnt revealed
> any information. I even checked and compared the COM commands used to
> control Excel from MATLAB and Python. But, still i am not able to
> progress any further. Moreover, the commercial software guys wont help
> me in doing with python. Furthermore, i used combrowse.py and make.py
> to access the different objects of the interface but they are all
> hidden for CST. Can someone suggest me how should i move ahead, are
> there any examples available for controlling a windows application
> through MATLAB and python so that i can understand the co-relation
> between the commands between the two. Any help in this regard is
> highly appreciated.
>
>
> Regards,
> GOWRISHANKAR.T.H
>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20170428/160aaa51/attachment-0001.html>
More information about the python-win32
mailing list