win32com and Passing SafeArrays of Doubles

Jeffrey N. Shelton shelton at custommachine.com
Fri Feb 15 18:09:07 EST 2002


In the process of using win32com to hook Python into SolidWorks (a 3D
modeler), I've run into the same problem as others before me -- namely, some
strange things happen when passing SafeArrays of doubles into SolidWorks.
Having created the appropriate gen_py file, I'm usually successful when I
pass in a tuple with the appropriate values. But when passing SafeArrays of
doubles into SolidWorks, it thinks I've inserted an extra value of 0.0
between each parameter I've passed. So it thinks that an array (1, 1, 1) is
instead (0, 1, 0, 1, 0, 1).

Past discussion at:
http://groups.google.com/groups?hl=en&selm=39943819.65368645%40news.onlineis
p.com

Mark Hammond's reply (back in August of 2000) indicated that he thought the
problem was with the SolidWorks code, and I'm quite willing to accept that.
However, I've noted from the SolidWorks API documentation (quoted below)
that, even when using VB, some special massaging is required.

So, do I have to do any special 'wrapping' to get SolidWorks to accept my
arrays, or does this still look like its just a shortcoming in the
SolidWorks implementation?

Any suggestions would be appreciated!

Jeff

>From SolidWorks API Documentation:
>
> Passing array data to SolidWorks in Visual Basic requires the use of a
> Variant variable to hold the data. The procedure is to put the data
> into an array then to assign a Variant to the array. The variant is then
> passed to an API function with parentheses round it:
>
>      Dim varArray As Variant
>      Dim DataArray(9) As double
>
>      ' Assign values
>      DataArray(0) = 0.1
>      ...
>
>      ' Pass the data to SolidWorks
>      varArray = DataArray
>      Result = Object.Method( (varArray) )  ' Note the extra parentheses
are required





More information about the Python-list mailing list