Poly Letter Kerning

On 20/08/2015 at 18:07, xxxxxxxx wrote:

Hello,
I'm trying to write a script for to align letters according to their bounding box xsize.
(Like in arrange command but depending on previous objects xsize)
For example each polygonal letters A,B,C have different xsizes. I want something like polygonal kerning:)
Problem:
https://www.dropbox.com/s/betsyjksb1y6zm3/alphabet0.jpg?dl=0

How it should look like (more or less) :
https://www.dropbox.com/s/pdjt4cp3f2t5vl5/alphabet1.jpg?dl=0

And my testing scene :
https://www.dropbox.com/s/lb34jrvh30q8691/scene_for_testing_script.c4d?dl=0

My code is :
(Note: All objects are centered to object axis, zero PSR and they are under a null as shown in the image above.)
I tried to assign objects into an array. But I stock around positioning them.
Please show me an example or check my script and note that I'm a beginner.😄
(P.S. I should solve that issue with Python Script because it will be another part of my main script...)
Thanks a lot.

import c4d
from c4d import Vector

def find_objects(op, objectarray) :
      
    objectarray.append(op)
    for child in op.GetChildren() :
        find_objects(child, objectarray)
 
def getsize(op,size) :
    
    size = op.GetRad()*2
    position = op.GetMp() + op.GetAbsPos()
    xsize = int(size.x)
    xsizearray.append((xsize))

def main() :
    
    global xsizearray
    
    objects = []
    size = []
    xsizearray = []
    position = []
    xpos = []
    for obj in doc.GetObjects() :
        find_objects(obj, objects)
    
    count = len(objects)
    
    for i in xrange (count) :
        getsize(objects _,size)
        
        print xsizearray _
        objects _.SetRelPos(c4d.Vector(xsizearray _,0,0))
        c4d.EventAdd()
    
main()

On 21/08/2015 at 02:13, xxxxxxxx wrote:

Hello,

I guess you would have to check if two letters collide and move them around until they don't collide anymore. In C++ there is the GeColliderEngine available that might be used. Currently this engine is not avialable in Python, so you have to develop an own solution.

Best wishes,
Sebastian

On 21/08/2015 at 03:15, xxxxxxxx wrote:

Hello,
Thank you for an answer,
What I need is something basic actually, those letters are polygons I'm calling them from specific library and merge them into a scene. Basically following letters should be located next to previous letter depending on its bounding box xsize.

I tried something, but it's moving all letters ( Sorry I'm a beginner:) )
Any advice please?

import c4d
from c4d import Vector

def find_objects(op, objectarray) :
      
    objectarray.append(op)
    for child in op.GetChildren() :
        find_objects(child, objectarray)
 
def getsize(op,size) :
    global xsize
    size = op.GetRad()*2
    position = op.GetMp() + op.GetAbsPos()
    xsize = int(size.x*2)
    xsizearray.append((xsize))
    
def move(op,sizex) : 
    pos = c4d.Vector(sizex,0, 0)
    op.SetRelPos(pos)
    
    
def main() :
    
    global xsizearray 
    objects = []
    size = []
    xsizearray = []
    for obj in doc.GetObjects() :
        find_objects(obj, objects)
    
    count = len(objects)
    
    for i in xrange (count) :
        getsize(objects _,size)
        move(objects _,xsizearray _)
    print ("Count of Objects " + str(count) )
    print ("Objects' X Size Valuess " + str(xsizearray) )
    
    c4d.EventAdd()
    
main()

On 21/08/2015 at 08:37, xxxxxxxx wrote:

Hello,

it seems that when you call "getsize" and "move" you hand over all objects and not a single object.

Best wishes,
Sebastian

On 24/08/2015 at 16:41, xxxxxxxx wrote:

I got you a working example at c4dcafe, as a reply to your post there, grasycho.

On 24/08/2015 at 23:53, xxxxxxxx wrote:

Thank you very much Rui:)