Grasshopper

algorithmic modeling for Rhino

Python: Keep getting an ArgumentTypeException I don't understand

To me it looks like combining the first and second pyCompoment should be easy and look like the third. But I keep getting an "ArgumentTypeException: expected int, got slice" I don't understand. Is this a bug or am I somewhat blind?

Views: 949

Replies to This Discussion

Hi Marcus

that's because CurveEditPoints(crv) returns a <type 'Point3dList'>, which is enumerable but does not support slicing. This collection is more memory-optimized for points, but has the disadvantage of being a little less friendly. I think in the future we could add slicing functionality to that class.

When something is not working like this, you should check with which type you are dealing, like, in this case, Point3dList, and not the usual Python list. You can then convert that special list this with a simple pts = list(pts), or  pts = [p in pts] or  pts = [p for p in pts].

I hope this helps,

Giulio

--

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

You can use a panel to display the contents of a wire/stream

That's the standard Python function for that job. As Python is dynamic, it's actually more difficult to recognize types as you write. We can try to improve the editor, though.

This is the code that runs in the background and provides you with CurveEditPoints:

rhinoscript CurveEditPoints (Python):

mcneel/rhinopython/../scripts/rhinoscript/curve.py

Then again that calls into RhinoCommon NurbsCurve (C#)

mcneel/rhinocommon/../dotnet/opennurbs/opennurbs_nurbscurve.cs

As you see it's often easier to just ask the type.

You also need that information once.

--

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Have you seen the Data Viewer?

View Menu > Data Viewer I assign Short Cut F12 to it

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service