win32com and Passing SafeArrays of Doubles

Mark Hammond mhammond at skippinet.com.au
Fri Feb 15 20:33:49 EST 2002


I believe it will simply be a matter of getting the correct "type tuple" 
in the generated code.  I am afraid I don't know VB well enough to know 
what the extra set of parens used by VB is.  It could be some special 
"byref" annotation, or maybe even specifying another level of 
indirection (ie, an array of arrays of doubles).

I suggest you try and determine exactly what that VB syntax does - you 
may then need to craft a type typle that indicates a 2 dimensional 
array, and actually pass ((1,2,3),) in your Python code.

Good luck, and feel free to mail if you need more help - getting this 
sorted would be good - we may even identify that pythoncom is being less 
then optimal <wink> in these edge cases.

Mark.

Jeffrey N. Shelton wrote:
> 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