On 05/08/2017 at 14:39, xxxxxxxx wrote:
Hi;
as I understand you, your object origin is initially okay, but the points are offset? In that case, you would need to correct the point positions relative to the object origin, not the object origin itself.
Point positions are stored as offsets relative to the containing object. Here is an example of how to handle and change point positions in a point object:
import c4d
from c4d import gui, Vector
def main() :
print "---------------------"
selectlist = doc.GetSelection()
for obj in selectlist:
print obj.GetName()
doc.StartUndo()
doc.AddUndo(c4d.UNDO_OBJECT, obj)
selected = obj.GetPointS()
maxelements = obj.GetPointCount()
counter = 0
average = Vector ()
for index, sel in enumerate (selected.GetAll(maxelements)) :
if sel==1:
average = average + obj.GetPoint(index)
counter += 1
average = average / counter
for index, sel in enumerate (selected.GetAll(maxelements)) :
if sel==1:
obj.SetPoint(index, average)
obj.SetDirty(c4d.DIRTY_DATA)
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()
This code is repositioning all selected points in a (selected) point object to a common average (essentially collapsing a point set to one position). It shows how to set a point with SetPoint() but also how to handle a selection on point and object level, how to set the Dirty flag, and how to include Undo.
In your case, you would not calculate an average but take the xmin, zmin values you already calculated in your code, and subtract that from each point position to affect the offset. The object itself would stay where it is, but all points would get moved.
Alternatively, you could use this average to calculate the center of the object's point cloud, and use that to correct the offset. This would center the points to the object's own position; depending on the necessary type of correction.