helloluxx

Paste As … Scripts for Cinema 4D

These scripts for Cinema 4D we are about to discuss are so useful, once you start using them you will never know how you lived without them, well ok, perhaps not life in general

These scripts for Cinema 4D we are about to discuss are so useful, once you start using them you will never know how you lived without them, well ok, perhaps not life in general, but your Cinema 4D life is going to become even more amazing than ever!

I’m not sure if you are aware but if you visit the Cinema 4D preferences, there is an option for pasting objects, in here we can choose from several options including Child & Parent.

Cinema 4D Preferences

I’m sure you’ve all been there, you copy an object from a scene, return to your working project — with it’s huge complex hierarchy of objects — hit paste and BAM! Where does your object go? At the top of the object manager, that’s where. Now you have the task of dragging that object down deep into the correct position of the Object Manager hierarchy, where it should have been in the first place.

One of the most convenient things in Cinema 4D is the fact you can select an object, then hold Alt and add a new object, that object will automatically become the parent of your previously selected object. You want to add a cube to a cloner, add a cube, hold Alt, add a cloner. Beautiful, it works and it makes our lives much easier. The same if you’d like an object to become a child, simply hold Shift as you add the new object and it will become a child of the selected object. This is super handy if you want to add a deformer to an object, saves all that dragging things around, plus if you use Release 15, the deformer will automatically fit the original object dimensions.

So, why can’t we do this when pasting? Well actually we can, although opening the preferences and changing the paste parameter each time you copy and paste is not exactly the most streamlined of workflows, is it? This is where scripting can be your best friend, why don’t we create a script to do this for us?

Now I must be honest here, my scripting skills are pretty poor, but luckily we have some very nice Cinema 4D users in the community who are willing to help. Credit for this task goes to both Rick Barrett from Maxon, US and Bret Bays, both of whom offered up solutions to this predicament.

The code / logic is actually really simple, first we get the preferences and store it in a variable.

bc = c4d.GetWorldContainerInstance() # Get the Prefs

Then we get the current paste settings and store this too as we’ll need it later.

oldPasteAt = bc[c4d.WPREF_PASTEAT] # Get the current Paste setting

Now the key part, we use Python to change the ‘Paste New Object At’ preference, the number you choose refers to the various options in the pop-up (don’t forget the menu starts at zero).

bc[c4d.WPREF_PASTEAT] = 4 # Set to Child

Next call the Paste command to paste our object.

c4d.CallCommand(100004821) # Paste

Finally we need to restore the original preference setting which we stored in a variable called oldPasteAt.

bc[c4d.WPREF_PASTEAT] = oldPasteAt # Reset the pref to original value

Put all of that together and the final script looks like this.


import c4d
from c4d import gui
#Welcome to the world of Python

def main():
bc = c4d.GetWorldContainerInstance() # Get the Prefs
oldPasteAt = bc[c4d.WPREF_PASTEAT] # Get the current Paste setting
bc[c4d.WPREF_PASTEAT] = 4 # Set to Child
c4d.CallCommand(100004821) # Paste
bc[c4d.WPREF_PASTEAT] = oldPasteAt # Reset the pref to original value

if __name__=='__main__':
main()

Save your script as PasteAsChild.py

Scripts are best stored in the library/scripts directory, if you’re not sure where that is then you can find a shortcut at the bottom of the preferences window, click the button on the left and this will open the preferences folder for you.

Preferences Button

You can change the value for this line to change this to Paste As Parent.

bc[c4d.WPREF_PASTEAT] = 3 # Set to Parent

Save this as a new script PasteAsParent.py

Create a script for all the paste types you use, paste as child and paste as parent are the two that I use most frequently.

The next thing to do is to assign keyboard shortcuts to these two scripts. To do this you need to open the Customise Commands dialogue.

Customise Commands

Then search for the PasteAs scripts, they’ll appear in the list. Select each command and assign it an appropriate shortcut, to keep things in line with the same shortcuts when adding new objects, I chose Shift-Command-V for paste as child and Alt-Command-V for paste as parent.

Assign Shortcut

After all this work the most important thing to do is to make sure you use the new commands. Try and get into the habit of using Cmd-Shift-V and Alt-Shift-V when you need to paste into a specific part of the hierarchy. Next time you use Cinema 4D without these scripts installed you’ll be reaching for your shortcuttable.res file! (That’s where all the shortcuts are installed.)

shortcuttable

You can grab the scripts here if you’ve got tired fingers and can’t manage to type all those lines of code…