Python – move a mesh using pythonscript

Hi Hossam,

You want to move your cube mesh from its centroid point to 0,0,0 point?
If that is so, try this:

import rhinoscriptsyntax as rs

def moveMesh():
    reqName = rs.GetString("Object of what name do you want to move")
    rs.Command("-_SelAll")
    objects = rs.GetObjects(preselect=True)
    if objects:
        for obj in objects:
            name = rs.ObjectName(obj)
            if name == reqName:
                if rs.IsMesh(obj):
                    centroid = rs.MeshVolumeCentroid(obj)
                    if centroid:
                        vector = rs.VectorCreate ([0,0,0], centroid)
                        rs.MoveObject(obj, vector)
                        print "Done"
                        break
                    else:
                        print "Something is wrong with your mesh. Function terminated"
                        return
                else:
                    print "You have not picked a mesh. Function terminated"
                    return
            else:
                if obj == objects[-1]:
                    print "Object of that name does not exist. Function terminated"
                    return
                continue
    else:
        print "Your file is empty. There's nothing to select"
        return

moveMesh()

EDIT: I added a bit of additional debugging.
Also when posting your code, you need to enclose it with python on the beginning, and at the end. This will format and highlight your code.
moveMesh.py (1.2 KB)