copy-paste script (loc/rot/size)

The following is a script that copies location, rotation and size from one or a group of objects and pastes it onto another object or group of objects.


#!BPY

"""
 Name: 'Copy/Paste'
 Blender: 232
 Group: 'Object'
 Tooltip: 'CopyPaste locrotsize form objects'
 """


import Blender
from Blender import Text


SelectedObjects = Blender.Object.GetSelected()

import Blender
from Blender import Draw

name = "|Copy|Paste"  
result = Draw.PupMenu(name)

if result==1:  

    copy=Draw.PupMenu("|Single|Group")

    if copy==1:

        try:
            txt=Text.Get('copysingle')
            Text.unlink(txt)
            txt=Text.New('copysingle')
        except:
            txt=Text.New('copysingle')
        
        
        self=SelectedObjects[0]
        pending=[]
        pending.append(self.LocX)
        pending.append(self.LocY)
        pending.append(self.LocZ)
        pending.append(self.RotX)
        pending.append(self.RotY)
        pending.append(self.RotZ)
        pending.append(self.SizeX)
        pending.append(self.SizeY)
        pending.append(self.SizeZ)
        for items in pending:
            txt.write(str(items))
            txt.write('
')

    if copy==2:
        try:
            txt=Text.Get('copymulti')
            Text.unlink(txt)
            txt=Text.New('copymulti')
        except:
            txt=Text.New('copymulti')
        
        for self in SelectedObjects:    
            pending=[self.name]
            pending.append(self.LocX)
            pending.append(self.LocY)
            pending.append(self.LocZ)
            pending.append(self.RotX)
            pending.append(self.RotY)
            pending.append(self.RotZ)
            pending.append(self.SizeX)
            pending.append(self.SizeY)
            pending.append(self.SizeZ)
            for items in pending:
                txt.write(str(items))
                txt.write('
')
        
        
    

elif result==2:
    paste = Draw.PupMenu("|Single|NameGroup|OrderGroup")
    if paste==1:
        self=SelectedObjects[0]
        txt=Text.Get('copysingle').asLines()
                
        single = Draw.PupMenu("|Loc|Rot|Scale|LocRot|LocRotScale")
        try:
            if single==1:
                self.LocX=float(txt[0])
                self.LocY=float(txt[1])
                self.LocZ=float(txt[2])
            elif single==2:
                self.RotX=float(txt[3])
                self.RotY=float(txt[4])
                self.RotZ=float(txt[5])
            elif single==3:
                self.SizeX=float(txt[6])
                self.SizeY=float(txt[7])
                self.SizeZ=float(txt[8])
            elif single==4:
                self.LocX=float(txt[0])
                self.LocY=float(txt[1])
                self.LocZ=float(txt[2])
                self.RotX=float(txt[3])
                self.RotY=float(txt[4])
                self.RotZ=float(txt[5])
            elif single==5:
                self.LocX=float(txt[0])
                self.LocY=float(txt[1])
                self.LocZ=float(txt[2])
                self.RotX=float(txt[3])
                self.RotY=float(txt[4])
                self.RotZ=float(txt[5])
                self.SizeX=float(txt[6])
                self.SizeY=float(txt[7])
                self.SizeZ=float(txt[8])
        except:
            Draw.PupMenu("%tNo Single Copy")
    if paste==2:
        txt=Text.Get('copymulti').asLines()
        single = Draw.PupMenu("|Loc|Rot|Scale|LocRot|LocRotScale")
        for self in SelectedObjects:
            itemNum=0
            for spud in txt:
                itemNum+=1
                if spud == self.name:
    
                    try:
                        if single==1:
                            self.LocX=float(txt[0+itemNum])
                            self.LocY=float(txt[1+itemNum])
                            self.LocZ=float(txt[2+itemNum])
                        elif single==2:
                            self.RotX=float(txt[3+itemNum])
                            self.RotY=float(txt[4+itemNum])
                            self.RotZ=float(txt[5+itemNum])
                        elif single==3:
                            self.SizeX=float(txt[6+itemNum])
                            self.SizeY=float(txt[7+itemNum])
                            self.SizeZ=float(txt[8+itemNum])
                        elif single==4:
                            self.LocX=float(txt[0+itemNum])
                            self.LocY=float(txt[1+itemNum])
                            self.LocZ=float(txt[2+itemNum])
                            self.RotX=float(txt[3+itemNum])
                            self.RotY=float(txt[4+itemNum])
                            self.RotZ=float(txt[5+itemNum])
                        elif single==5:
                            self.LocX=float(txt[0+itemNum])
                            self.LocY=float(txt[1+itemNum])
                            self.LocZ=float(txt[2+itemNum])
                            self.RotX=float(txt[3+itemNum])
                            self.RotY=float(txt[4+itemNum])
                            self.RotZ=float(txt[5+itemNum])
                            self.SizeX=float(txt[6+itemNum])
                            self.SizeY=float(txt[7+itemNum])
                            self.SizeZ=float(txt[8+itemNum])
                    except:
                        Draw.PupMenu("An Error Occured%t")
    if paste==3:
        txt=Text.Get('copymulti').asLines()
        single = Draw.PupMenu("|Loc|Rot|Scale|LocRot|LocRotScale")
        itemNum=1
        for self in SelectedObjects:                        
            try:
                if single==1:
                    self.LocX=float(txt[0+itemNum])
                    self.LocY=float(txt[1+itemNum])
                    self.LocZ=float(txt[2+itemNum])
                elif single==2:
                    self.RotX=float(txt[3+itemNum])
                    self.RotY=float(txt[4+itemNum])
                    self.RotZ=float(txt[5+itemNum])
                elif single==3:
                    self.SizeX=float(txt[6+itemNum])
                    self.SizeY=float(txt[7+itemNum])
                    self.SizeZ=float(txt[8+itemNum])
                elif single==4:
                    self.LocX=float(txt[0+itemNum])
                    self.LocY=float(txt[1+itemNum])
                    self.LocZ=float(txt[2+itemNum])
                    self.RotX=float(txt[3+itemNum])
                    self.RotY=float(txt[4+itemNum])
                    self.RotZ=float(txt[5+itemNum])
                elif single==5:
                    self.LocX=float(txt[0+itemNum])
                    self.LocY=float(txt[1+itemNum])
                    self.LocZ=float(txt[2+itemNum])
                    self.RotX=float(txt[3+itemNum])
                    self.RotY=float(txt[4+itemNum])
                    self.RotZ=float(txt[5+itemNum])
                    self.SizeX=float(txt[6+itemNum])
                    self.SizeY=float(txt[7+itemNum])
                    self.SizeZ=float(txt[8+itemNum])
                itemNum+=10                
            except:
                itemNum+=10    

It saves the properties to two txt objects in blender, one for a single copy, one for a group copy. For paste OrderGroup, it pastes based on the order the objects were selected in. For paste NameGroup, it pastes based on the objects name.

Hmm, how’s that different from what ‘Copy Attributes’ [ctrl + c] does?

Copy Attributes copies more than location, rotation, and size, but it it copies by copying the attributes from one object directly to the others on the same frame and all at once.

This script saves the attributes to be used later, so you can copy the objects attributes from one frame to another. Also, this works with groups of objects, so you can select multiple objects, copy their attributes, then paste those attributes to either the same objects (e.g. on a different frame) or paste the attributes to a different series of objects so the location of multiple objects can be switched easier.

Oh, I see. Neat.