Problem with moving points - Python Script in Rhino


#1

Hi, I’m fairly new to using python in Rhino, and I’m having trouble writing a function to move an existing point anywhere in the top view. To me, everything checks out, but when I select the point I want to move and the point I want to move it to, I get the error "Message: Parameter must be a Guid or string representing a Guid."
The code I have now is:

import rhinoscriptsyntax as rs

def move_point():
point = rs.GetPoint(“Select a point to move.”)
new_point = rs.GetPoint(“Select where to move the point.”)
vector = rs.VectorCreate(new_point, point)
return rs.MoveObject(point, vector)

move_point()

PS: There isn’t an indenting issue, in my code everything in the function is indented, it’s just I couldn’t figure out how to do it here.


#2

The problem is that GetPoint() returns point coordinates, not a point OBJECT. If you wish to move an existing point object, use rs.GetObject with the filter 1 (for point object) to get the object, then extract it’s coordinates with either rs.PointCoordinates() or rs.coerce3dpoint()…

import rhinoscriptsyntax as rs
def move_point():
    pointID = rs.GetObject("Select a point to move", 1, preselect=True)
    point=rs.PointCoordinates(pointID)
    #or rs.coerce3dpoint(pointID)
    new_point = rs.GetPoint("Select where to move the point.")
    vector = rs.VectorCreate(new_point, point)
    return rs.MoveObject(pointID, vector)
    
move_point()

To format your code in your posts here, put 3 backticks in the line before it followed by “python”

```python
<your code>
```

then 3 more backticks after your last line of code…

Oh, and in Rhino Python, you do not really need rs.VectorCreate() - you can add and subtract 3d point objects, which automatically creates a 3dvector object:

rs.MoveObject(pointID, new_point-point)

–Mitch