[python-win32] scripting Rhino via win32com

Jelle Feringa / EZCT Architecture & Design Research jelle.feringa at ezct.net
Fri Apr 22 12:26:58 CEST 2005


Hi all,

I'm trying to script Rhino -a 3d CAD nurbs modeler- via python.
Which looks to be very cool, if it wasn't for some gnarly problem I'm
running into:

from jf.interface import RhinoScript #interface to rhino by makepy
import os, sys, win32com.client

Rhino = win32com.client.Dispatch("Rhino3.Application")
time.sleep(1)
Rhino.Visible = True
RS = Rhino.GetScriptObject
RS = RhinoScript.IRxRhino(RS)

So far so good.
Now if I use RS.AddLine((0,0,0),(10,10,10)) -which produces a line from 2
coords- all works well.
Too bad that when I have to use an array of points all goes wrong:
RS.Curve(points,degree)
RS.AddCurve(((1,2,3),(4,5,6),(7,8,9)),3)
---
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "c:\Python23\lib\site-packages\jf\interface\RhinoScript.py", line 48,
in AddCurve
    return self._ApplyTypes_(77, 1, (12, 0), ((12, 0), (12, 16)),
'AddCurve', None,vaPoints, vaDegree)
  File "c:\Python23\lib\site-packages\win32com\client\__init__.py", line
446, in _ApplyTypes_
    return self._get_good_object_(
com_error: (-2147352567, 'Exception occurred.', (6, 'RhinoScript_m', 'Type
mismatch in parameter.  One-dimensional array required.', 'C:\\Program
Files\\Rhinoceros 3.0\\RhinoScript_m.HLP', 393222, 0), None)
---


Even when I use it own method of getting points -via the GUI- I get the same
error:
RS.AddCurve(RS.GetPoints(),3)
---
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "c:\Python23\lib\site-packages\jf\interface\RhinoScript.py", line 48,
in AddCurve
    return self._ApplyTypes_(77, 1, (12, 0), ((12, 0), (12, 16)),
'AddCurve', None,vaPoints, vaDegree)
  File "c:\Python23\lib\site-packages\win32com\client\__init__.py", line
446, in _ApplyTypes_
    return self._get_good_object_(
com_error: (-2147352567, 'Exception occurred.', (6, 'RhinoScript_m', 'Type
mismatch in parameter.  One-dimensional array required.', 'C:\\Program
Files\\Rhinoceros 3.0\\RhinoScript_m.HLP', 393222, 0), None)
---

More in detail:
s = RS.GetPoints()
s
((-7.0, -30.0, 0.0), (15.0, -24.0, 0.0), (-7.0, 12.0, 0.0), (14.0, 29.0,
0.0), (28.0, 10.0, 0.0), (20.0, 1.0, 0.0))

Cool, I get to choose points in the GUI, right back into python, wicked!
Though when I send these points back to the app:
RS.AddPolyline(s)
The same error all over again:
---
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "c:\Python23\lib\site-packages\jf\interface\RhinoScript.py", line
129, in AddPolyline
    return self._ApplyTypes_(85, 1, (12, 0), ((12, 0),), 'AddPolyline',
None,vaPoints)
  File "c:\Python23\lib\site-packages\win32com\client\__init__.py", line
446, in _ApplyTypes_
    return self._get_good_object_(
com_error: (-2147352567, 'Exception occurred.', (6, 'RhinoScript_m', 'Type
mismatch in parameter.  One-dimensional array required.', 'C:\\Program
Files\\Rhinoceros 3.0\\RhinoScript_m.HLP', 393222, 0), None)
---

RS.AddPolyline(((1,1,1),(2,2,2),(3,3,3)))
Again, the same error persists.

So this leaves me to believe that the problem lies in sending the array to
the app... Now I have no idea to solve this... but having too much fun to
give this up... any suggestions?

Cheers,

Jelle.



More information about the Python-win32 mailing list