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, 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…

Author: Tim

17 Comments

  1. John 4D
    John 4D On July 3, 2014 at 3:30 PM

    THANK YOU! This was awesome.

  2. Joel
    Joel On October 9, 2014 at 4:01 PM

    Hey,

    I just started with this company working on illustrations and 3d modeling and this is the first time I have ever been introduced to coding. It all sounds like spanish too me right now but The people i work i consider geniuses when it comes to how they approach a project. They work with use a lot of open based 3d modeling software and they really try to emphasize the use of code to solve fairly complex tedious and monotonous tasks. I cant talk much about the project but This is a great addition to my workflow and will help me out in the future.

    Thank you for writing this.

    sincerely

    Joel c boyer

    • admin
      admin On October 9, 2014 at 4:08 PM

      Joel, perhaps you should try and use Xpresso in your projects as it is much more accessible than scripting and will really help to streamline workflow. Thanks for the positive comment!

  3. Toby
    Toby On December 6, 2014 at 10:21 AM

    Now that’s handy!! Cheers Tim! 🙂

  4. Kris Cook
    Kris Cook On January 5, 2015 at 2:51 PM

    Thanks Tim, this is freaking grand.

    Out of interest, in your screenshot, you also have PasteAsParent_BB & PasteAsPrevious.

    What do those do?

    cheers

    • admin
      admin On January 19, 2015 at 12:48 PM

      Sorry for the late reply, I missed this comment. The other scripts are the same as paste as child except they paste as parent, previous etc. The _BB is because the script was written by Bret Bays.

      • Kris Cook
        Kris Cook On January 21, 2015 at 9:21 PM

        Same same 🙂 a reply is a reply in my world, no matter how long it takes. Unless it’s a client owning me cash.

        Seeing as though you pimp a lot of tutorials series’s – do you have anything available that could get me up and running in Python ?

        I’m an ex honky flash AS 2 coder(more hatching though wasn’t it) – so I my way around a For Loop or two.

        Dauwd’s blowing my mind of late.

        • admin
          admin On January 22, 2015 at 10:20 AM

          Hey Kris, I’m sorry but we do not offer any Python training at all 🙁

  5. Alex
    Alex On April 25, 2015 at 1:47 PM

    This will save quite a few clicks. =)
    thanks

  6. Jesus
    Jesus On September 12, 2015 at 5:45 AM

    For some reason is not working for me. It’s not compiling. Gimmes me a
    SyntaxError: bc = c4d.GetWorldContainerInstance() # Get the Prefs
    Line:5 Position:2

    I’m using R16

    • admin
      admin On September 14, 2015 at 10:31 AM

      Did you type it or download the script? It works for me in R16

  7. Jesus
    Jesus On September 15, 2015 at 3:47 AM

    I copied and pasted it. I’ll give it another try.

    • Jesus
      Jesus On September 15, 2015 at 4:11 AM

      Works perfectly now, Thanks

  8. Abdullah
    Abdullah On September 30, 2015 at 11:56 PM

    Actually there is an easier way to do it with only three command lines!

    Paste As Parent command lines:

    prefs(465001620)#PREF_INTERFACE_PASTEAT=3;
    CallCommand(12108); // Paste
    prefs(465001620)#PREF_INTERFACE_PASTEAT=0;

    Paste As Child command lines:

    prefs(465001620)#PREF_INTERFACE_PASTEAT=4;
    CallCommand(12108); // Paste
    prefs(465001620)#PREF_INTERFACE_PASTEAT=0;

    Finally, save your scripts and assign some shortcuts to them.

    • admin
      admin On October 1, 2015 at 1:55 PM

      Thank you for posting.

      It’s true you can do it with three lines. The difference is, the script I use stores the user’s preferences, then returns them back to their previous state after pasting. Your code presumes that the user hasn’t changed the preferences as it resets to the default value.

  9. navstar
    navstar On March 22, 2017 at 10:05 AM

    Can’t seem to get this to work in R18. I copy an object so there’s something in my clipboard. I select another object (like a null). I run the script….. and nothing is pasted. Curious if other R18 users can get it to work?

    Also your download link is broken (http://luxx.tv/pasteas)

Leave a Reply