Trying to write a script (more as a learning thing) in python to

take a selection of points

find the average position

find the closest point to the average point, measure it D

then pull/push all the selected points D away from the average point

sort of circle points script

stuck on the last 2 items in the list

Help appreciated (this code is collected from various online sources)

especially taking into account the position of the source object - I can never recall how to add that into the calculation

Code:

import c4d import os import math from c4d import gui """ --------FUNCTIONS------------- """ def GetSelectedPointIDs(PointObj): if PointObj is None: c4d.gui.MessageDialog("Please Select one Point Based Object") return elif not PointObj.CheckType(c4d.Opoint): c4d.gui.MessageDialog("Please Select one Point Based Object") return else: listy=[] pointlist=[] maxEl=PointObj.GetPointCount() bs=PointObj.GetPointS() for index, selected in enumerate(bs.GetAll(maxEl)): if not selected: continue else: listy.append(index) pointlist.append(PointObj.GetPoint(index)) return listy, pointlist def VAvg(lv): """ Calculate the average of a list of vectors. """ if not isinstance(lv, list): raise TypeError("E: expected list of c4d.Vectors, got %s" % type(lv)) res = c4d.Vector(0,0,0) if len(lv) == 0: return res for l in lv: res.x += l.x res.y += l.y res.z += l.z res.x = res.x / float(len(lv)) res.y = res.y / float(len(lv)) res.z = res.z / float(len(lv)) return res """ --------MAIN------------- """ def main(): ob = doc.GetActiveObject() if ob == None: return mg = op.GetMg() pt_ids, pt_vects = GetSelectedPointIDs(ob) if len(pt_ids) <3: print "less than three points - need more" return print pt_ids # the list of point indexes print pt_vects # the list of point vectors AVPV = VAvg(pt_vects) # the avarage vector print AVPV # the avarage vector # help - find the closest point to the average point AVP - measure the distance # help - move all selected points the same distance away from AVP # help - math to take into account the global position etc if __name__=='__main__': main()