Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Questions on COM Objects scripting

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


<mmhamze at pleiades

Sep 3, 2001, 10:38 AM

Post #1 of 6 (474 views)
Permalink
Questions on COM Objects scripting

I have couple of questions regarding client scripting against COM objects
using Pythonwin, and using Python in an ActiveScripting setting. All I need
are hints to direct me in the right direction.
1. Using PythonWin-
I am controlling a povray modeller program (Breeze Designer) that has a COM
interface in the form of:
"Breeze.Scene"

import win32com.client
scene=win32com.client.Dispatch("Breeze.Scene")
# This all works fine. Now we continue with
from win32com.client import pythoncom
scene1=pythoncom.Connect("Breeze.Scene")
# I get the following error"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
com_error: (-2147221021, 'Operation unavailable', None, None)

Taking into account that the very same thing works fine with something like
"Excel.Application"; what does this error tell me about "Breeze.Scene"?

2. Using Python ActiveScripting
From inside the applicatio itself (Breeze Designer) there is a facility to
run Macros with languages with ActiveScripting capabilities including
Python.
"Breeze.Scene" is created automatically when Breeze is started.
a macro starts with $Scripting_Language

So
$Python
Breeze.Scene.New()

give me a Python error that Breeze is not defined. So does Scene.New().
I just can not get Python to communicate with this interface.
If I use
$Python
import win32com.client
scene = win32com.client.Dispatch("Breeze.Scene")

The application is crashing with an error in Pythoncom21.dll

Breeze allows by default for VBScript to get the object without further
trouble.
The question:
I do not know if this is a problem with Breeze OR the way I am doing to get
the object to be used with Python. maybe: import win32com.client is not
the way.
If this is not a problem with Breeze, what can we use to communicate with
this object so that Python can be used with it?
Thanks,
Maan


MarkH at ActiveState

Sep 3, 2001, 6:32 PM

Post #2 of 6 (456 views)
Permalink
Questions on COM Objects scripting [In reply to]

Maan Hamze wrote:

> Taking into account that the very same thing works fine with something like
> "Excel.Application"; what does this error tell me about "Breeze.Scene"?


That Breeze.Scene is not registering itself in the "Running Object
Table". This should not be a problem - the fact that Excel works is
more unusual than the fact that Breeze.Scene does not.

> 2. Using Python ActiveScripting
> From inside the applicatio itself (Breeze Designer) there is a facility to
> run Macros with languages with ActiveScripting capabilities including
> Python.
> "Breeze.Scene" is created automatically when Breeze is started.
> a macro starts with $Scripting_Language


"Breeze.Scene" should not be created automatically - that would suck.
Hopefully what you mean is that a "Breeze" object is created, and it
should have a "Scene" attribute.

You could try printing "globals()" to see exactly what is in the
ActiveScripting namespace. If "Breeze.Scene" really does exist in the
namespace, then we will need to pull some tricks to work around a very
poor decision by the povray people.

Keep in mind that VB is not case sensitive, but Python is. Have you
tried "breeze"?

Mark.


<mmhamze at pleiades

Sep 3, 2001, 8:49 PM

Post #3 of 6 (454 views)
Permalink
Questions on COM Objects scripting [In reply to]

Mark
Thanks for your reply. If you can give me some hints to the following, I'll
have all the ideas I need to be able to tell Breeze Designer developer what
is going wrong with his implemetation of Python ActiveScripting macro
capability. I am quite sure now that it is quite buggy and hopefully he can
fix things.
My first question:
Breeze Desinger comes with Type Library used for reference. The file is:
Breeze20.tlb. I was able to load it in Visual Basic 6.0 (from the
References menu by browsing and choosing the tlb file) and look at the
methods and properties of the scene object.
However in PythonWin:
>>> from win32com.client import pythoncom
>>> pythoncom.LoadTypeLib("d:\winpov\breeze\program\Breeze20.tlb")
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
com_error: (-2147312566, 'Error loading type library/DLL.', None, None)

Breeze20.tlb is used as a reference file. Why can't PythonWin load it?
Now for the rest of the post:

"Mark Hammond" <MarkH [at] ActiveState> wrote in message
news:3B942FF4.9040006 [at] ActiveState
> Maan Hamze wrote:
> > 2. Using Python ActiveScripting
> > From inside the applicatio itself (Breeze Designer) there is a facility
to
> > run Macros with languages with ActiveScripting capabilities including
> > Python.
> > "Breeze.Scene" is created automatically when Breeze is started.
> > a macro starts with $Scripting_Language
>
>
> "Breeze.Scene" should not be created automatically - that would suck.
> Hopefully what you mean is that a "Breeze" object is created, and it
> should have a "Scene" attribute.
>
My mistake Mark. It was a Typo. This is what the Breeze doc mentions:
"All functions are available though the Breeze Designer **scene** object.
This
object is pre-created when using macros **from within Breeze Designer**.
That is
to use any on the following functions a scene. should be added to the front
of the function."

> You could try printing "globals()" to see exactly what is in the
> ActiveScripting namespace. If "Breeze.Scene" really does exist in the
> namespace, then we will need to pull some tricks to work around a very
> poor decision by the povray people.
>
Actually Breeze Designer is a povray modeller, but it is not done by the
povray people. It translates a scene/model into povray syntax.
From inside Breeze Designer I had the macro:
$Python
import win32traceutil
from win32com.client import Dispatch
print globals() #to print into the Python Trace Collector of PythonWin
scene=Dispatch("breeze.scene") #notice small case letters :)
rest of code......

Is that the usual way of getting the object when scripting inside an
application (not through PythonWin)? What I do not like about this program
is that with VBScript, scene object seems to be given. But with other
scripting languages one has to be able to get the object. So there must be
some default implementation that allows VBscript to see it, but for Python
to get it before using it (otherwise Python reports that scene is not a
defined name).

Please note that I used "breeze.scene" this time. I was using
"Breeze.Scene" before because that is what is in the Windows Registry (it is
not listed in PythonWin COM browser so I looked in the registry, found it,
and used it.) And Breeze.Scene was working while scripting from within
PythonWin. So it would never have occured to me to use breeze.scene.
1. breeze.scene IS working now from within a macro in Breeze. But Breeze
is still crashing sometimes and it got nothing to do with Python. The
problem is with Breeze Designer when it tries to open the OpenGL Perspective
window.
2. That is what I am getting in the Python Trace Collector (by using print
globals() in the macro):
{'ax': <win32com.axscript.client.pyscript.AXScriptAttribute instance at
02A815BC>, 'win32traceutil': <module 'win32traceutil' from
'd:\python\win32\lib\win32traceutil.pyc'>, 'Scene':
<NamedItemAttribute<ScriptItem at 44574700: Scene>>, etc......etc.........

So, yep, it is....... Scene (not scene). But it is breeze.scene that is
working not Breeze.Scene.
Maan


MarkH at ActiveState

Sep 3, 2001, 11:54 PM

Post #4 of 6 (450 views)
Permalink
Questions on COM Objects scripting [In reply to]

Maan Hamze wrote:

>>>>from win32com.client import pythoncom
>>>>pythoncom.LoadTypeLib("d:\winpov\breeze\program\Breeze20.tlb")
>>>>
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> com_error: (-2147312566, 'Error loading type library/DLL.', None, None)


Note that you have single backslashes, and the "\b" is being translated
to ASCII 8.

> My mistake Mark. It was a Typo. This is what the Breeze doc mentions:
> "All functions are available though the Breeze Designer **scene** object.
> This
> object is pre-created when using macros **from within Breeze Designer**.
> That is
> to use any on the following functions a scene. should be added to the front
> of the function."


OK - so "scene.whatever" should work.

> Actually Breeze Designer is a povray modeller, but it is not done by the
> povray people. It translates a scene/model into povray syntax.
> From inside Breeze Designer I had the macro:
> $Python
> import win32traceutil
> from win32com.client import Dispatch
> print globals() #to print into the Python Trace Collector of PythonWin
> scene=Dispatch("breeze.scene") #notice small case letters :)
> rest of code......


For ActiveScripting applications, the "scene" object should magically
appear. There should be no need to create such an object manually.
ActiveScripting itself defines how this magic happens.


> Please note that I used "breeze.scene" this time. I was using
> "Breeze.Scene" before because that is what is in the Windows Registry (it is
> not listed in PythonWin COM browser so I looked in the registry, found it,


COM itself is not case sensitive. So the string passed to Dispatch()
generally does *not* care about case.

However, the documentation for the ActiveScripting support implies that
a magic variable called "scene" should already be setup for you. As
with any other Python variable, the case does matter.

So if the documentation is correct, then "scene.whatever" should work
without any need to use the Dispatch() function.


> 2. That is what I am getting in the Python Trace Collector (by using print
> globals() in the macro):
> {'ax': <win32com.axscript.client.pyscript.AXScriptAttribute instance at
> 02A815BC>, 'win32traceutil': <module 'win32traceutil' from
> 'd:\python\win32\lib\win32traceutil.pyc'>, 'Scene':
> <NamedItemAttribute<ScriptItem at 44574700: Scene>>, etc......etc.........
>
> So, yep, it is....... Scene (not scene). But it is breeze.scene that is
> working not Breeze.Scene.


OK - so "Scene.whatever" should work :) Forget everything about
"Breeze.Scene". Assume that magically code similar to:

Scene = Dispatch("Breeze.Scene")

has already been executed, and just start using the "Scene" variable.

Mark.


mmhamze at pleiades

Sep 4, 2001, 6:40 AM

Post #5 of 6 (457 views)
Permalink
Questions on COM Objects scripting [In reply to]

"Mark Hammond" <MarkH [at] ActiveState> wrote in message
news:3B947B51.6070709 [at] ActiveState
> Maan Hamze wrote:
>
> >>>>from win32com.client import pythoncom
> >>>>pythoncom.LoadTypeLib("d:\winpov\breeze\program\Breeze20.tlb")
> >>>>
> > Traceback (most recent call last):
> > File "<interactive input>", line 1, in ?
> > com_error: (-2147312566, 'Error loading type library/DLL.', None, None)
>
>
> Note that you have single backslashes, and the "\b" is being translated
> to ASCII 8.
>
:O
Ok! I see!
Taking into account that this is the first time ever I use COM in Python,
one is apt to drop many backslashes on the way :)
>
> > 2. That is what I am getting in the Python Trace Collector (by using
print
> > globals() in the macro):
> > {'ax': <win32com.axscript.client.pyscript.AXScriptAttribute instance at
> > 02A815BC>, 'win32traceutil': <module 'win32traceutil' from
> > 'd:\python\win32\lib\win32traceutil.pyc'>, 'Scene':
> > <NamedItemAttribute<ScriptItem at 44574700: Scene>>,
etc......etc.........
> >
> > So, yep, it is....... Scene (not scene). But it is breeze.scene that is
> > working not Breeze.Scene.
>
>
> OK - so "Scene.whatever" should work :) Forget everything about
> "Breeze.Scene". Assume that magically code similar to:
>
> Scene = Dispatch("Breeze.Scene")
>
> has already been executed, and just start using the "Scene" variable.
>
Now I have the complete picture. Of course globals() is reporting the
object Scene before anything else is dispatched etc..... So it is already
there.
The problem is that I have tried every combination in the book including the
direct use of scene, and Scene then Dispatch("Breeze.Scene") etc... etc.....
scene, and Scene alike (without using any Dispatch) are causing Python to
report that Scene (or scene for this matter) are undefined names. This is
strange since Scene IS there. I may have an idea for what is happening!
Ok! That is what I wanted to make sure of that PythonWin is not the culprit
here. So time to give the developer a call and let him know about this :)
Thanks Mark,
Maan


MarkH at ActiveState

Sep 4, 2001, 4:19 PM

Post #6 of 6 (454 views)
Permalink
Questions on COM Objects scripting [In reply to]

Maan M. Hamze wrote:

> Now I have the complete picture. Of course globals() is reporting the
> object Scene before anything else is dispatched etc..... So it is already
> there.
> The problem is that I have tried every combination in the book including the
> direct use of scene, and Scene then Dispatch("Breeze.Scene") etc... etc.....
> scene, and Scene alike (without using any Dispatch) are causing Python to
> report that Scene (or scene for this matter) are undefined names. This is
> strange since Scene IS there. I may have an idea for what is happening!
> Ok! That is what I wanted to make sure of that PythonWin is not the culprit
> here. So time to give the developer a call and let him know about this :)


What does "print Scene" yield?

Mark.

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.