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

2019-06-12 Thread Jayesh Jain
Hey Max,
How did u manage to run the VB scripts to control CST via python
Can you help me out with that

Thanks and Regards
Jayesh Jain
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


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

2017-04-28 Thread Max Landaeus

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@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


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

2017-04-28 Thread Tim Roberts
On Apr 27, 2017, at 11:17 PM, gowri shankar  
wrote:
> 
> I checked both the ways without any success. By the by, mws.EigenmodeSolver() 
> works perfectly in MATLAB. Does the object name changes with different 
> language.

It's not impossible.  You're using late binding here, which has to find the 
entry points by doing a text search.  However, the web seems to indicate that 
your spelling is correct.


> Can you please suggest any literature or source where i can learn more on COM 
> .

There are an infinite number of books and websites on COM; the technology has 
been around for more than 20 years.  However, the different language bindings 
do have different requirements and implications, so a C++-based book will be 
good background information, but won't help specifically with Python.

As an experiment, you might try using EnsureDispatch instead of just Dispatch.
from win32com.client.genache import EnsureDispatch
That creates and saves a Python module to interface to the object.  Sometimes 
having that module can be helpful in debugging.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


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

2017-04-28 Thread Tim Roberts
On Apr 27, 2017, at 12:02 PM, gowri shankar 
> wrote:

Thanks for bringing out my inadequacies.  By the by i am using Python 2.7.8 
|Anaconda 2.1.0 (64-bit).
Here are the error codes for the same:

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

That string is still wrong, by the way.  You NEED to fix the backslashes.
—
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


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

2017-04-27 Thread Tim Roberts
gowri shankar wrote:
>
> Thanks for bringing out my inadequacies.  By the by i am using Python
> 2.7.8 |Anaconda 2.1.0 (64-bit).
> Here are the error codes for the same:
>
> import win32com.client
> *cst* = win32com.client.Dispatch("CSTStudio.Application")
> #Opens a new CST file
> *mws*=*cst*.OpenFile('D:\Gowrishankar\PDF\cuboid.cst')
> ##
> *mws.StoreParameter('len2',10.1)
> *
> *mws.StoreParameter("s",5)*
> ##I don't get any error message for them. And usually this should
> store a variable and its values in CST but it didn't do
> *Esolver=mws.EigenmodeSolver()*
> *### I got the following error message*
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Anaconda\lib\site-packages\win32com\client\dynamic.py",
> line 192, in __call__
> return
> self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
> pywintypes.com_error: (-2147352573, 'Mitglied nicht gefunden.', None,
> None)

That's 0x80020003, DISP_E_MEMBERNOTFOUND, meaning that it did not find
the name in its dispatch table.  Are you absolutely sure you have the
spelling correct?  Could it be EigenModeSolver, for example? 
Capitalization matters.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


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

2017-04-27 Thread Tim Roberts
gowri shankar wrote:
>
> /*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');/
> /...
> /
>
> 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.

You are still only giving us about 1/4 of the information we need in
order to help you.  It doesn't do any good to show is the MATLAB code
you started with.  We need to see the Python code you created, and we
need to see the error messages you get.  The COM error messages might
seem inscrutable to you, but the large negative numbers in there are
specific COM error codes.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


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 
wrote:

> On Tue, Apr 25, 2017 at 6:48 PM, Tim Roberts  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


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

2017-04-25 Thread Joni Orponen
On Tue, Apr 25, 2017 at 6:48 PM, Tim Roberts  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


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

2017-04-25 Thread Tim Roberts
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')

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32