Archive for the “Scripting” Category

I don’t update this enough. Life does that sometimes.

Lately, I’ve been toying around with streaming via twitch.tv to help educate folks about rigging in CINEMA 4D. I just work on stuff I want to work on and people can come and ask questions and I can demonstrate stuff. I’ve done 2 of them now. This second one produced a couple of nifty little things I can share with the community.

The first is a skateboard rig(As me rigging a skateboard was the idea for rigging improv I did). The model came from Valentine Bertrand’s skateboard rig for Maya. So all credit goes there, not to me. You can download the skateboard rig and play around with it from here: CINEMA 4D  Skateboard Rig  It was rigged in R16, but it should probably work in older versions as well.

The second thing the night brought was a simple script I wrote to demonstrate some python for people watching. It’s nothing special but it might be useful to people. It’s commented to hell too so it should be easy to understand what’s going on. It basically takes whatever you have selected, and for each object selected, it will create a circle spline, and constrain the selected object to the circle spline. You can get the script here: CreateControlsForSelectedObjects

Comments No Comments »

Hey everyone, I’ve gone forth and released a new plugin of mine called Marker Manager. There was a post about it not too long ago, but now it’s available for purchase here: http://c4dtools.net/marker-manager/

Please check it out, tell your friends, and if it looks useful to you, give it a purchase. Your support leads to more scripts and plugins I can work on.

Thanks guys,
Bret

Comments No Comments »

Here’s a couple of scripts I came up with this week. Both very simple, but very useful, so I thought I’d share them for folks to use/learn from. So I took a break from some other Python related things(in relation to templates and thinking particles) and thought I’d write up a little something about them and post them. Enjoy!

EXTRUDE ‘EM ALL

Extrude ‘Em All is a script aimed at those of you who work with a lot of splines. You probably have done the process of creating an ExtrudeNURBS, adding them all as children and turning on Hierarchical. Or Maybe you hit ALT+G to Group them into a null, then ALT+Clicked to create an ExtrudeNURBS as the parent(since it doesn’t work with multiple objects afaik) and turned on Hierarchical. Well, This is a bit simpler. Select your splines, run the script. Boom, they’re all a child of an ExtrudeNURBS with hierarchical turned on. Lowering the amount of time/clicks.

GROUP EACH

Group Each is a helper script I made while I was rigging a car. ALT+G(or the Group Objects command) is incredibly helpful. If done on a single object you get a parent null at the same location as it’s child. With multiple objects selected, it does the Average. It’s essentially the same as ALT+Clicking on a Null, but again, it doesn’t work with multiple objects, and sometimes, I don’t need it to do the average, I want each thing selected to get it’s own parent null. Now it can. Select your objects, run the script, each will get a null parent with the same name with “_algn” which is sort of my rigging suffix for a null that just rests at the same place as it’s child.

So have fun with them, maybe they are of some use. If you find them incredibly useful, consider dropping a little donation found on the right, but otherwise just try to learn some python from them.

Cheers,
Bret

Comments No Comments »

Hello Everyone,

Since Python was implemented in R12 I’ve been working on an Auto-Rigging system. It was mostly done as a training exercise to learn various things in Py4D. It’s taught me A-LOT about python, now I’ve decided to share it with the community both as a tool for those who need a rig quickly, and as a learning device for people interested in Python, since I’m going to leave the code open for you to explore.

It’s released sort of as is. If you find glaring issues with them, I’ll try to fix it, but it’s meant to be as is because I am running low on time to devote to it.

So please enjoy and consider donating for the time spent working on the scripts and leaving it open for you and others to learn from.

The scripts and donation button can be found on the right side of the homepage.

A Video demonstration can be found at http://www.bretbays.com/b3Auto-Rig.mov

adjrigThis Image shows the Adjustment Rig that has been fit to a character

fullrigThe Completed Rig based off of the Adjustment Rig

You can download the B3 Auto-Rig Scripts from Here

If you feel they have been helpful, please consider donating.





Cheers,
Bret

Comments No Comments »

So, I would like to edit my previous python snippet, because I discovered something that didn’t make it work particularly well which I will try to explain and show you how to fix it. Thanks to Rick for telling me how to make it work properly, and then telling me again after I forgot to save the code somewhere.

picture-6

This is my hierarchy. Now, our script was supposed to just go down our selected object’s hierarchy. Which at first glance it does. But, it doesn’t quite work. If you select object named 2(not 2A) and run the script, it prints from 2-16. But it shouldn’t since 10-16  are are not actually children of 2, they are siblings. I want to run through a hierarchy of a selected object. This becomes more apparent when you select 1, and see as it prints 1-16, AND ABC. Whaaaat!? So, my fault, I should have tested it better. Actually, I did. I tested it thoroughly which is how I found the problem ;) . I should have waited to write about it.

Anyway, so the solution was presented to me by Rick, so thanks for that. The fix is easy.

def GoDownHierarchy(obj):
if obj is None: return

#Actions can go here
print (obj.GetName())
#End Actions
if (obj.GetDown()):
GoDownHierarchy(obj.GetDown())
if (obj.GetNext()):
GoDownHierarchy(obj.GetNext())

That’s our Code where we left off. We just need to adjust it a little bit. First, in order for this to work, we need to specify where we want this to stop. So we need to pass a second argument that mentions where we want to stop. So our first line will be changed to:

def GoDownHierarchy(obj, stop):

So now we need to check to see if we’ve reached the stop point. So we need a little check in there after our initial “if obj is None” check:

...
if obj is None: return
if obj==stop: return
...

Now, the last thing we need to, is update our function elsewhere in the code. Remember we do two more checks(if statements) and they run the function again, so since we need two arguments, we need to put in the stop argument in both.

So the whole Code for the function is now:

def GoDownHierarchy(obj, stop):
if obj is None: return
if obj==stop: return
#Actions can go here
print (obj.GetName())
#End Actions
if (obj.GetDown()):
GoDownHierarchy(obj.GetDown(), stop)
if (obj.GetNext()):
GoDownHierarchy(obj.GetNext(), stop)

So if you want to run this on the selected object’s hierarchy you would type:


GoDownHierarchy(op, op.GetNext())

So with that code, if I select object 2 in my hierarchy and run it, it goes from 2-9. Since 10 and onward is not a child of 2, it does not get printed.

Enjoy.

Comments No Comments »

I’ve been diving into Python a lot lately, just because there are things you just want to be able to do yourself. I’ve been talking to a buddy of mine, Charles Wardlaw who is the TD overseer of the Ottoman, and works at March Entertainment. He sometimes challenges me with Python exercies, and sometimes I ask him for ideas(which he offers and they become challenges.)

So between bugging him and Rick, I have been learning a lot of Python in CINEMA 4D. Charles gives me a lot of the theory side of things as well as the standpoint of him being a TD and an Animator he knows how he’d like some scripts to behave, while Rick helps me with SDK stuff in CINEMA. He’s been programming in COFFEE so he knows where to look to find stuff and how to do things. He too is getting into Python. So I usually try to find something and if I have no luck I ask Rick and he usually has a solution.

Which leads me to these useful snippets. Initially the idea was how to copy animation from some objects to other objects. This was originally based on hierarchy(it has now changed) so I needed a way to basically go through an entire hierarchy and perform some action on the object and all it’s children.


def GoDownHierarchy(obj):
if obj is None: return
#Actions can go here
print (obj.GetName())
#End Actions
if (obj.GetDown()):
GoDownHierarchy(obj.GetDown())
if (obj.GetNext()):
GoDownHierarchy(obj.GetNext())

Now unfortunately, wordpress is kind of killing the necessary tabbing for this to work. But allow me to try to explain what’s going on a bit.

So the first line, def GoDownHierarchy(obj): is just defining our function in Python, no biggie, and it’s also saying when you call this function it needs argument, in this case it’s going to need some kind of object. The next line, if obj is None: return is just a simple check that if you don’t pass an object, nothing happens. Without this, if you passed the function without an object, it should error out I think. After that check, you can put your actions in there. In this case, I’m simply printing out the names of the objects in the hierarchy, nothing fancy.

So after the action we have another if statement: if (obj.GetDown()): This is basically checking to see if there is there is an object as a child of the current object. If there is, it goes to the next line: GoDownHierarchy(obj.GetDown()) This line basically runs the function again. So if the code gets to this line, it goes all the way back to the 3rd line of this code and performs the action again on the object that is a child of the current obj. So effectively when it hits that line, it running the function and passing a new object(obj.GetDown()) to run the function. Then it does this again and again until there is no longer a child and the if (obj.GetDown()): line is FALSE. If it is false, it goes to another if statement if (obj.GetNext()): This line is checking to see if there is a Sibling of the last obj passed to the function. If it is TRUE it will run GoDownHierarchy(obj.GetNext()) which like before it is passing obj,GetNext() into the GoDownHierarchy Function which then causes it to go through the GetDown() conditions(the if statements) so it will go down that hierarchy as well.

So here’s an example of how it works. Here’s an example of my OM. You can see I have Cube 2 selected.

picture-7

I run the script and I get this in the console:

picture-8

Note that it didn’t get the numbers 1,14, 15, or 16, because they are not siblings or children.If I took 14 and 15(which also takes 16) and made them a child of 1, this would make them siblings, would this make them be included? Well, that depends. If the siblings are ABOVE the selected object, they won’t be printed. If they are below the selected object, then yes, it will work. Easy Peasy right?

Now, what if you want to actually go UP the hierarchy? For instance, what if you need to find the top root of a selected object? Well that’s easy, you can take this same code, you just have to make 2 little changes. Here’s the Code:


def GoUpHierarchy(obj):
if obj is None: return
#Actions can go here
print (obj.GetName())
#End Actions
if (obj.GetUp()):
GoUpHierarchy(obj.GetUp())
if (obj.GetPred()):
GoUpHierarchy(obj.GetPred())

So obviously if you’re going to go up your hierarchy you don’t want it named “GoDownHierarchy”. So You’ll see each reference to the function’s name has been changed to “GoUpHierarchy”. Besides that, you need to make some changes. Instead of GetDown() you need to use GetUp(), and instead of GetNext() you gotta use GetPred(). That’s it! Easy cheese!

Comments 4 Comments »