Rs.MoveObject() + rs.CopyObject() methods usage issue

Hi,

I have been puzzled for the last few days, why my GH Python code is not working.

What I want to do is to copy a row of curves between two points. Like this:

Here is the code that does not work (“a” and “b” are input points, “N” is the number of curves between those two points, “curve” is the initial input curve):

import rhinoscriptsyntax as rs

vect = rs.VectorSubtract(b,a)
vect1 = rs.VectorDivide(vect,N)

a = []
for i in range(0,N):
    vect = rs.VectorScale(vect1,i)
    movedCurve = rs.MoveObject(curve,vect)
    a.append(movedCurve)

For some reason it works only when I add the rs.CopyObject method inside of rs.MoveObject, like so: (line 9):

import rhinoscriptsyntax as rs

vect = rs.VectorSubtract(b,a)
vect1 = rs.VectorDivide(vect,N)

a = []
for i in range(0,N):
    vect = rs.VectorScale(vect1,i)
    movedCurve = rs.MoveObject(rs.CopyObject(curve),vect)
    a.append(movedCurve)

Why is that so?
Basically in the first code, I am moving the initial curve, iteratively one by one vector and in each iteration I am appending that moved curve into the export “a” list. So why do I have to use the rs.CopyObject method too?

I attached the .gh file with both upper code present in it, and the .3dm with just two points and a curve.

Thank you.

copy curve between 2 points.gh(4.2 KB)

copy curve between 2 points.3dm(49.5 KB)

Well, the answer is that MoveObject does not create a NEW object - you are moving the original. So you are just appending the same object ID to your list, and in the end, you will have only the last position of the object.

I think you should just be able to use the following (haven’t tested i in GH though, this is how it works in normal Python):

a = []
for i in range(0,N):
    vect = rs.VectorScale(vect1,i)
    copiedCurve = rs.CopyObject(curve,vect)
    a.append(copiedCurve)

–Mitch

1 Like

Aha. I did not know that (about the rs.MoveObject not creating a new object but, instead just moving the original one). It must have something to do with my understanding of grasshopper, where each data is copied (the Move component in grasshopper copies and moves that copy).

And yes, your code works perfectly in GH, just checked it.

Thanks Mitch.