Posts Tagged “Python”

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 »

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 »

I’ve been so busy at work, with Kai and Amanda leaving, and other projects that I never got to post any Pics from my trip to New York City. I had a blast. I loved it there. CCW was pretty good too. Anyway, here’s some choice pics from the trip.

Me and Libby in Times Square

Me and Libby in Times Square

No Mugs for us

No Mugs for us

Radio City Music Hall

Radio City Music Hall

Playing the Big Piano

Playing the Big Piano

Grimaldi's

Grimaldi's

Hey! BB, that's me!

Hey! BB, that's me!

In addition to CCW, I also had a blast at SpiNYC or the MAXON Mixer. Totally cool place. I also got to meet Mike Stamm, head of The Ottoman Project(www.the-ottoman.com/blog) face to face which was nice. Wish I had more time to hang out and chat with Mike who’s a great guy.

Speaking of the Ottoman, I’ve gotten in an insane rigging mode for the Ottoman the last 2 weeks. When Mike mentioned it took almost half a year to Rig The Ottoman Character, I was baffled, because I know it doesn’t take me that long to rig. But you know what? The Ottoman rig was a serious learning project that took a lot of time to solve particular problems.

Now that those problems have been solved, I pretty much said I could rig the remaining 3 main characters in 1-2 days each. I’m happy to report that The Rider was done over the course of 2 days, the Wife in one, and I’ve spent about 5 hours on The Son rigs. The Wife and Rider will need more weighting focus, but the rigs are ready. The Son needs a few things in the Arms, then Hand Rigs, Mirror, and auto-weighting. Then all primary character rigging is essentially done. Exciting!

I plan on finishing the Son tomorrow, but I might have a Rugby Tournament in Santa Barbara so it could put a hinder on that…

OK, it’s about 2:50 AM I should go to bed. Be on the look out for some interesting Python experiments. I’ve been learning Python in CINEMA 4D like a madman and coming up with some cool stuff.

Comments No Comments »