Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Poly Letter Kerning

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 427 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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()

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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()

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                Thank you very much Rui:)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post