PythonWin, COM, SolidWorks, Huh?

William Wicker remove.me.wwicker at spectratechnologies.com
Fri Aug 11 13:44:36 EDT 2000


I have been experimenting with Python as a scripting language for
SolidWorks as time allows. For the most part, I'm quite pleased with
what I see.

Every so often, there is something that makes me scratch my head a
bit. I attach below an example.

#----------------------------------------
PythonWin 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on
win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Portions Copyright 1994-2000 Mark Hammond (MHammond at skippinet.com.au)
>>> import win32com.client
>>> swx = win32com.client.Dispatch("SldWorks.Application")
>>
>>> doc = swx.ActiveDoc
>>> matl = doc.MaterialPropertyValues
>>> matl
(0.752941176471, 0.752941176471, 0.752941176471, 1.0, 1.0, 1.0,
0.3125, 0.0, 0.0)
>>> doc.MaterialPropertyValues = matl
>>> matl
(0.752941176471, 0.752941176471, 0.752941176471, 1.0, 1.0, 1.0,
0.3125, 0.0, 0.0)
>>> doc.MaterialPropertyValues
(0.0, 0.752941176471, 0.0, 0.752941176471, 2.00926476482e-313,
0.752941176471, 2.00926476482e-313, 1.0, 2.00926476482e-313)
>>> 
#-----------------------------------------------

MaterialPropertyValues is documented to return/accept a variant
SAFEARRAY of doubles.

Solidworks does not automatically support the makepy interface
(bummer) and will not do so this century (bummer again).

Unfortunately, it looks like the trip from Python to Solidworks
mangles the numbers in an unfriendly way. It looks like extra zeros
have been interspersed among the existing tuple elements.

I am running PythonWin build 129.

Any comments or suggestions to overcome this would be appreciated.

Thanks

	William.



More information about the Python-list mailing list