algorithmic modeling for Rhino

Hi. I'm  new to python and I would like to know the easiest way to make a copy of a list of points in a grasshopper python component.

The python way newPointList=oldPointList[:] doesn't seem to work. Which makes sense as a list of point coordinates is a list of lists, isn't it?

That's why I tried:

for oldpoint in oldpoints:

But now I get a RuntimeError (see attached file example).

I finally made it work by copying every component of every point in the list seperately. But there has to be a simpler way.

(The example file is about moving a bunch of circles horizontally so that their centers lie on the y-axis.)

Thanks for your advice!

Views: 3576


Replies to This Discussion

You should be able to simply use list() like so:

# The original list
list1 = [1,2,3,4]

# Copy the list
list2 = list(list1)

# Change list items
list2[0] = 0
list1[0] = "hu"

# Check result
print list1,list2
print id(list1),id(list2)

There is also a standard Python module for more advanced copy functionality.

Ps. I only got an error in your GH file due to the circles not being internalized (i.e. they were Null). Not quite sure what you are trying to do though.

Thanks a lot!

I made it work with the list() function. This means you always have to convert a list of on3dpoints first into a list of lists and then back to on3dpoints again to get a copy of it.

Did I get that right?


Not sure I follow, on3dpoints is deprecated as far as I know. I have put together a small example of how I would approach your problem (assuming I understood it correctly). See the attached file. I'm using straight up RhinoCommon to construct the circles but you can easily replace that with Rhinoscriptsyntax if you prefer. Also I'm using a pattern where one constructs an empty list and populates this from within a loop instead of first copying the input list.


If you do not need the original circles within the script you could make it even simpler by moving them in-place. See attached.


Thanks again. Very helpful and interesting.

Well, the circle issue was more of an example for why I want to copy a list of points than an actual problem...

Anyways. Obviously I have to do some very basic reading (about RhinoCommon for instance).

The .Radius and .Center commands that you applied on the circles: where can I find a list of those?

Those two are properties for the "Circle" type:

Hey djordje!

So you got up to learning Rhinocommon? How is it going? Which language do you code in? Best

As Djordje says they are properties of a type (specifically Rhino.Geometry.Circle). This is lingo used in Object Oriented Programming. I wouldn't worry about that too much for now, just know that when you are using geometry types in Grasshopper or Rhino Python you are using classes from the RhinoCommon .NET SDK. I would recommend reading/watching some introductory tutorials (1,2,3) on this subject though, should be enough to build a basic understanding of how RhinoCommon and OOP works.

Regarding accessing information about a type. This is called introspection and Python has some pretty nifty ways of going about it. See the attached example. Hope that helps..



this seems to work for RhinoCommon Point3d objects

newpoints = [ Rhino.Geometry.Point3d( p ) for p in oldpoints ]

Great! That's what I was looking for.

And thank you Anders and Djordje for your helpful advice!

Hey! make sure you understand the difference between shallow copy and deep copy of a list.

I read this python clone list tutorial and it was very easy to understand the difference.

Remeber that copying your list of points could bring issues if you do a shallow copy or unexpected result.

hope it helps!






  • Add Photos
  • View All


  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service