PDA

View Full Version : Align multiple axis' towards a centre target


dflamholc
05-22-2012, 12:37 PM
Hi all,
I've desperately searched for scripts and ideas on this here and other places, but have drawn a complete blank.

I have a field of polygons created by importing an illustrator file, extruding it 1 unit and then making it editable, current state to object, splitting it etc.
http://imageshack.us/photo/my-images/854/screenshot20120502at184.png/

At the moment all these polygons have their X axis pointing in the same direction.
http://imageshack.us/photo/my-images/576/screenshot20120522at132.png/
http://imageshack.us/photo/my-images/37/screenshot20120522at132.png/
What I would like to be able to do is to push the axis of each individual polygon towards the back edge of respective polygon (the edge furthest away from the centre of the whole group) at the same time as targeting the X or Z axis of each polygon towards this group centre - without changing alignment of the polygons themselves.

I wish I was able to say that I had got further in my own experiments trying to active this, but I am either missing something incredibly obvious, or I simply have no idea how to approach this. I presume xpresso or even coffee script is needed(?)

Thanks in advance for any advice!
cheers David

NiklasR
05-22-2012, 01:39 PM
Hello dflamholc,

unfortunately I don't quite understand what you want to do. Can you somehow visualize your problem (Video or similar?)

Best,
Niklas

dflamholc
05-22-2012, 02:03 PM
Hi Niklas,
Thanks for your reply! and apologies complicating the issue unnecessarily.

I simply want to align a lot of different objects axises towards the centre of the group (null), without actually rotating the object themselves. Once all the (for example) X axises point in towards the centre of the screen, then I'd like to offset all the the axises on the -X (away from the centre).

Hope that makes it clearer. Were you able to look at the images?

Cheers
David

fuat
05-22-2012, 02:18 PM
what do you want to achieve after aligning the axes?

fuat
05-22-2012, 02:19 PM
then I'd like to offset all the the axises on the -X (away from the centre).
David

that still would do nothing. yoiu only would move the axes around without any effect.
or do i misunderstand?
i guess you want to move the polys, not the axes?

dflamholc
05-22-2012, 02:36 PM
Mark,
thanks for your reply!

No no, i want to re-position the axises only. Polys are to stay put where they are in their grid.
Once all ploys axis are repositioned, I will be able to modify the ploys based on this new axis.
thanks
david

NiklasR
05-22-2012, 02:42 PM
So, theoretically, this would mean adding a "Target" Tag to each object pointing to the middle of the scene, but it only modifies the axis (so polys stay where they are)?

-Nik

tcastudios
05-22-2012, 02:44 PM
The following will rotate each (polygon) child's axis
to the parent. (The part about placing the axis "furthest away"
is not included here, to much atm)

Cheers
Lennart

# PointAxisOnly tcastudiosĐ2012
# Points the axis of selected Point Objects to the parent ( or scene center if no parent)
# and keep points at original local(parent) position

import c4d
from c4d import Vector as v, utils as u

def main():
sobjs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
if not sobjs[0]:
return True

t = sobjs[0].GetUp()# the parent

try:
tm = t.GetMg()
except:
tm = c4d.Matrix()

doc.StartUndo()

for o in sobjs:
if o.CheckType(c4d.Opoint):
oldm = o.GetMg()
points = o.GetAllPoints()
pcount = o.GetPointCount()

doc.AddUndo(c4d.UNDOTYPE_CHANGE, o)
o.SetAbsRot(u.VectorToHPB(tm.off-oldm.off))
o.Message(c4d.MSG_UPDATE)

newm = o.GetMg()

for p in xrange(pcount):
o.SetPoint(p,~newm*oldm*points[p])

o.Message(c4d.MSG_UPDATE)

c4d.EventAdd()
doc.EndUndo()

if __name__=='__main__':
main()


NOTE the notorious misspelling by the board, look at "SELECTIONORDER"
and edit in script manager

Edit, correction, tnx nux.

dflamholc
05-22-2012, 02:48 PM
Yes exactly! now that'd be a pain if we were talking about 1000-2000 ploys, so I was hoping to understand how to do this by iterating through the children of a null/cloner (mo data node?) and thus be able to get control over the axis of each individual poly and add a target to each respective poly's axis etc...
would that be possible? I don't seem to be able to figure out a way to do this.
thanks!
david

dflamholc
05-22-2012, 02:51 PM
Thanks Lennart,
i will try this out straight away.
thanks!
David

fuat
05-22-2012, 03:00 PM
now itīs clear.
afaik you cant access the axes in expresso driectly, but i think itīs possible with cofee.
the re-alignment of the polys themselves (not the axes!) can be done very well in expresso, but one needs basic knowledge of vector-math and matrices.

EDIT: just saw Lennartīs post...

NiklasR
05-22-2012, 03:23 PM
@Lennart: You are missing a () within the except-clause. An if-else would've worked, too. :)
I suggest to paste code on services like pastebin.com (http://pastebin.com) or similar, as the board often breaks the code.

http://pastebin.com/wpadR7wS

Cheers,
Nikkas

dflamholc
05-22-2012, 03:36 PM
Niklas, thanks for that as well!

Lennart's script works great, but I tried yours as well with the same result.

This is actually the first time I use python, as i usual manage what i need to do with xpresso. the great news for me, which was slightly unexpected, is that once the axises have been modified with the script, I can delete the python tag and then shift the axises to the back with Centre Axis tool. I didn't expect that ;)
thanks for all your help!
cheers
David

tcastudios
05-22-2012, 03:51 PM
Beware it's a script that is meant to be run from the ScriptManager,
not an expression tag. While it might work, things must be written
a bit different to be on the safe side.

Cheers
Lennart

dflamholc
05-22-2012, 04:02 PM
oh i see :blush: well i started pasting it into a coffee tag and that didn't work at all haha
so then i tried a python tag and that did the trick without any too obvious caveats.
i did stumble across the script manager as well tho, so i'll read up on that separately.
thanks again!
David

CGTalk Moderation
05-22-2012, 04:03 PM
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.