[python-win32] passing array by reference (3)

Andreas Holtz A.Holtz at gmx.net
Sun Feb 19 10:23:25 EST 2017


Hi Peter,

>From Python call Catia.SystemService.Evaluate() and hand over a VB script that does what you need
but returns an Array.

This works for all CATIA methods that use an Array as Input/Output-parameter.

Regards

Andreas


Peter Enenkel schrieb am 17.02.2017 um 23:29:
> Hello All,
> 
> 
> 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
> <https://mail.python.org/pipermail/python-win32/2002-November/000562.html> and
> (2)https://mail.python.org/pipermail/python-win32/2014-July/013234.html
> <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
> The equivalent VBScript code is
> Dim a(11) As Float
> CATIA.ActiveProduct.Position.GetComponents(a)
> MsgBox a(0) & ", " & a(1) & ...
> The VBScript works as intended, the python one just passes the array back out unmodified.
> 
> As both other threads state: The Position object above has two methods *GetComponents *and
> *SetComponents *that each take a *CATSafeArrayVariant *as an argument. This *CATSafeArrayVariant
> *should in this case be a one-dimensional array of real values. CATSafeArrayVariant is a typedef for
> a *CATVariant *which itself is *typedef any CATVariant*.
> 
> Any help would be appreciated. As stated above I haven't done much with COM, but otherwise I'm
> reasonably computer savvy and know my way around python. Obviously Catia is a commercial application
> but I have access to the .tlb file if that helps.
> 
> 
> best regards
> Peter Enenkel
> 
> 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
> 


More information about the python-win32 mailing list