Solved Copy Paste Point Global Position

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

@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

@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

@cairyn
It Works. Thank You. Very Much.