CGTalk > Software > Maxon Cinema 4D
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 09-18-2013, 11:53 AM   #1
deepshade
Expert
portfolio
Paul T
United Kingdom
 
Join Date: Aug 2008
Posts: 1,245
Moving points help pls

Its always the same - I spend a long time away from Python and when I get back to it I can't remember how to do stuff (or its just beyond me in the first place)

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()
 
Old 09-18-2013, 12:59 PM   #2
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
this snippet might answer some questions. i do not really understand what your last step
is meant to be , so i did skip it (pushing the points away).

http://codepad.org/GK8Two4k

edit : about the pushing, i do not really understand what you want to do. but basically
you would have to do this (assuming all point vectors are in the same space) as
pseudocode :

http://codepad.org/H9DceBY7
__________________
There are holes in the sky. Where the rain gets in.
But they're ever so small. That's why the rain is thin.

Last edited by littledevil : 09-18-2013 at 01:18 PM.
 
Old 09-18-2013, 01:30 PM   #3
deepshade
Expert
portfolio
Paul T
United Kingdom
 
Join Date: Aug 2008
Posts: 1,245
Take selection
find the average point (mid point)
Store 'mid point'
Find the closest point in the selection to the 'mid point'

Push/Pull.....

Move (pull) each of the other points towards the 'mid point' (in a line from where they are now) so they are the same distance away from the mid point.

Last edited by deepshade : 09-18-2013 at 01:33 PM.
 
Old 09-18-2013, 03:13 PM   #4
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
http://codepad.org/IOE0N7Nk

that does more or less what you have desribed. select a point object, optionally select
some points and the they will be moved to a fixed distance to their common average point.
pressing shift or ctrl while executing the script will calculate the average point just within
the selected points, without a modifier key all points are used to determine the average
point.

pretty much the same the spherify modifier is doing.



script executed on some points of a cube, left cube without modifier key, right with modifier
key (inclusive / exclusive average point)
__________________
There are holes in the sky. Where the rain gets in.
But they're ever so small. That's why the rain is thin.

Last edited by littledevil : 09-18-2013 at 03:36 PM.
 
Old 09-18-2013, 05:15 PM   #5
deepshade
Expert
portfolio
Paul T
United Kingdom
 
Join Date: Aug 2008
Posts: 1,245
Thanks littledevil,

I'll take a look

Edit - That's great - does what I wanted and a great resource to learn from

much appreciated

atb

Last edited by deepshade : 09-18-2013 at 05:35 PM.
 
Old 09-18-2013, 05:15 PM   #6
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:23 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.