Re: [python-win32] To control commercial software CST through python

2017-04-27 Thread gowri shankar
Thanks for the suggestion guys.

But, my problem is, i am able to open CST from Python but other commands
which works in MATLAB don't work in python.

MATLAB commands**
*cst = actxserver('CSTStudio.application') % to open the CST*
*mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst'); %to open a
particular file*


Python commands*
*import win32com.client*
*cst = win32com.client.Dispatch("CSTStudio.Application")*
*#Opens a new CST file*
*mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');*


*a=20;*
*b=20;*
*c=72;*
*%To store the parameters*


*I was not able to convert these following MATLAB commands into python. I
got errors. *
*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"']);*


"I tried different online forums for help and i was unsuccessful in getting
any clue how to move forward. Error messages didn't 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
Contact No:+4917641783894

On Tue, Apr 25, 2017 at 7:00 PM, Joni Orponen <j.orpo...@4teamwork.ch>
wrote:

> On Tue, Apr 25, 2017 at 6:48 PM, Tim Roberts <t...@probo.com> wrote:
>
>> gowri shankar wrote:
>> > 
>> **
>> >
>> > 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');/
>>
>> You can't use backslashes like that in a Python string literal.  You
>> need to use one of following:
>>
>> mws = cst.OpenFile('D:/Gowrishankar/PDF/cuboid.cst')
>> mws = cst.OpenFile('D:\\Gowrishankar\\PDF\\cuboid.cst')
>> mws = cst.OpenFile(r'D:\Gowrishankar\PDF\cuboid.cst')
>>
>
> Using os.path.join() is also a valid alternative pattern for operational
> safety and consistency.
>
> import os
>
> os.path.join(
> 'D:',
> os.path.sep,
> 'Gowrishankar',
> 'PDF',
> 'cuboid.cst')
>
> >>> 'D:\\Gowrishankar\\PDF\\cuboid.cst'
>
> --
> Joni Orponen
>
> ___
> python-win32 mailing list
> python-win32@python.org
> https://mail.python.org/mailman/listinfo/python-win32
>
>
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] To control commercial software CST through python

2017-04-24 Thread gowri shankar
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@python.org
https://mail.python.org/mailman/listinfo/python-win32