Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Copy Paste Point Global Position

    Cinema 4D SDK
    python
    2
    3
    460
    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.
    • ymoonY
      ymoon
      last edited by

      I want copy point position(World) & paste to Other Object's Point(World).
      The coordinate manager can displays the World-Position values. but there is no copy paste function.
      You can use the Snap function of C4D, but I want to reduce even one click.

      I want to create two scripts and assign a shortcut key to each.(copy / pate)
      Python is not easy. Ask for help.

      import c4d
      
      def main():
      
          sel_pt = op.GetPointS()
          id_sel_pt = 0
      
          for i in range(op.GetPointCount()):
               if sel_pt.IsSelected(i):
                   id_sel_pt = i
      
          objectmg = op.GetMg()
          selgmg = op.GetPoint(id_sel_pt) * objectmg
          print(selgmg)
          
          c4d.CopyStringToClipboard(selgmg) 
      
      if __name__ == '__main__':
          main()
      

      Paste Clipboard --> c4d.GetStringFromClipboard()
      Move Point --> op.SetPoint(id,c4d.Vector())

      CairynC 1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn @ymoon
        last edited by

        @ymoon

        selgmg is a c4d.Vector, while GetStringFromClipboard expects a string, so Python uses the str function to convert, which results in an unwieldy string like
        Vector(50, 0, 0)
        If you want to put that string back into a vector, you need to parse it - I don't think there is an API function that does that.

        However, you can solve the parsing issue pretty quickly by putting a JSON string to the clipboard instead which represents the three components of the vector:

        import c4d
        import json
        
        def main():
        
            sel_pt = op.GetPointS()
            id_sel_pt = 0
        
            for i in range(op.GetPointCount()):
                 if sel_pt.IsSelected(i):
                     id_sel_pt = i
        
            objectmg = op.GetMg()
            selgmg = op.GetPoint(id_sel_pt) * objectmg
            selgmgStr = json.dumps([selgmg.x, selgmg.y, selgmg.z])
            print(selgmg, selgmgStr)
            
            c4d.CopyStringToClipboard(selgmgStr) 
        
        if __name__ == '__main__':
            main()
        

        Then the readback would be just as easy:

        import c4d
        import json
        
        def main():
        
            selgmgStr = c4d.GetStringFromClipboard() 
            selgmgList = json.loads(selgmgStr)
            selgmg = c4d.Vector(selgmgList[0], selgmgList[1], selgmgList[2])
            print(selgmg, selgmgList, selgmgStr)
            
            sel_pt = op.GetPointS()
            id_sel_pt = 0
        
            for i in range(op.GetPointCount()):
                 if sel_pt.IsSelected(i):
                     id_sel_pt = i
        
            objectmg = op.GetMg()
            op.SetPoint(id_sel_pt, selgmg * ~objectmg)
            
            op.Message (c4d.MSG_UPDATE)
            c4d.EventAdd()
        
        if __name__ == '__main__':
            main()
        

        Python for C4D scripting:
        https://www.patreon.com/cairyn

        ymoonY 1 Reply Last reply Reply Quote 1
        • ymoonY
          ymoon @Cairyn
          last edited by

          @cairyn
          It Works. Thank You. Very Much.

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