Peter Enenkel wrote:
>
> I'm trying to read some data from CATIA v5 (which is an older CAD
> application) via its COM server. Overall it works rather well, even if
> I'm fairly new to COM communication.
>
> Nevertheless I have run into a problem: One specific function
> *GetComponents * is supposed to return its results via an array passed
> by reference. As far as I can tell it is exactly the same problem as
> in
> (1)https://mail.python.org/pipermail/python-win32/2002-November/000562.html
> and
> (2)https://mail.python.org/pipermail/python-win32/2014-July/013234.html
> unfortunately there doesn't appear to be a solution as of yet.
>
> The python call looks something like this
> a = list(range(0,12))
> b = catapp.ActiveProduct.Position.GetComponents(a)
> print(a) # outputs (0,1,2,3,4,5,6,7,8,9,10,11) instead of the actual
> values

Usually, in this kind of situation, the array would be an output parameter:

    b, a = catapp.ActiveProduct.Position.GetComponents()

Remember that Python doesn't actually do pass-by-reference in the way
you are used to.  In your code above, you aren't really passing "a". 
What you're passing is the list that "a" is bound to.  The Python COM
code converts that into whatever type the function wants.  If that array
gets changed, it doesn't change the list.  It can't, because that
parameter might actually have been a tuple, which can't be modified, and
there is no way for the function to change the binding of "a".  That's
why the COM stuff usually returns the changed parameter, so you can
change your binding.

Do you have the actual function signature in C++ or IDL form?  If they
haven't declared it properly, PythonCOM might not be able to determine
that this is an output parameter.

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

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

Reply via email to