Hey there. Welcome to scripting for artists.
This is a video tutorial series on scripting blender,
it is aimed at people who don't necessarily want to be a programmer,
but for whom scripting may be beneficial
and it can be useful for a lot of things as we'll see soon
before we start. Let me introduce myself. My name is super unstable.
I'm core blender developer and I've worked at the blender
institute so I have experienced working next to artists.
I've worked on the blender cloud itself and I've worked on a tractor and Flamenco.
I also have a PhD in computer animation during
which I worked on the blender game engine.
And after that I started working here at the blender Institute.
So about this series,
it's about scripting blender basically letting blender push its own buttons.
If you've ever done any dumb monkey work that takes
a lot of clicks and a lot of repetition.
This may be the series for you.
Examples were scripting would be useful are mass renaming of bones
or objects or rendering 10,000 LBJ files in some directory.
One thing to keep in mind is that computers are stupid.
They will just do what they're told line by line,
word by word and not really think about what you mean.
So it's good to keep in mind that you have to be literal.
So that's it for the introduction of this series.
Let's go and do something practical in blender itself.
Let me can be programmed in python and that's quite a nice language that can be read
and understood quite easily for the more it
allows you to interactively toy around with it.
So let's dive into blenders python console.
Well after I changed my shirt, that is
so here is the default startup file.
We can replace the timeline with the python console
because we don't need a timeline right now.
Let's do some computations
three times four equals 12 to plus three times four equals
14 because multiplication and division go before addition and subtraction.
So if you want to do the addition first,
you have to use parentheses to place two times four
Equals 20. Let's go and see if we can do something to that default cube.
If we press an interview part for the numerical data you can see locations X, Y and Z.
Let's move it somewhere else.
So if you hover your mouse over the location, you can see some python information.
Be part of data objects cube location zero,
which basically means from blenders python interface.
Get the data in. There are objects from those objects. I want to have cube
cube has a location, location, has a few components, this is component zero,
Why is component one and that is component to
So we can just copy this into our blender python console. P pi data objects cube,
Location zero and that gives us the x location
and location one gives us the wind location and of course to will give us the said
alternatively you can use letters.
So there is actually a dot X do exactly the
same thing and I like those a little bit better.
It makes your script a bit easier to read if you just name them, X, y and z.
This isn't limited to reading. We can also write to it so we can set
taught, set to zero
and then it's back at zero
or one
or we can use
Plus equals, which means increment
by increment by 0.1
and we can keep using this.
I'm pressing the up arrow key
in the console that gives me the previous command and then press enter.
So you don't have to type everything by hand. Again
we can also assign to the location
directly instead of to each component individually
by removing the last component and then assigning it three numbers in parenthesis.
So for example like this
and then we've set X, y and z at the same time.
This also worked for scale.
Okay.
Mhm.
And it also works for the rotation.
Yeah,
except that on the pattern side of things, rotations always work with radiance
and not with degrees that she might stay in the user interface.
So this might get a little bit getting used to
one more thing that may make things a little bit easier to type.
Is that the python console supports auto completion.
So you can do be pie dot de and then compress control space dot org
cube. You have to type yourself but then rotation and then
so this is done with control space. It can be really useful.
It can also help you figuring out what is there to type in the first place.
So there's a whole list of things here.
This you can find in the documentation by the way,
if you go to help and then python api reference then you
get all this information but we'll cover that in a moment.
Let's look at some other things we can find about python.
In blenders user interface. We have seen these properties of existing objects.
So let's see if we can delete and maybe create some new objects.
This is done with operators and operators are blenders way of
binding certain functionality to menu items or buttons in the interface.
So what we can do is just hover over button and then you see the operator command.
You don't even have to remember it. You can just press control C. To copy
and then press control V. To paste it into the console and it will just work.
So now we've deleted an object. Let's take a look at creating one.
You can just press shift a then over an operator
however your mouse and you see be pointed up.
Stop messed up primitive UV sphere ad
So again press control C.
And then in the console press control V and enter and there you have your sphere.
It's a bit boring one is the default one.
So let's see if we can do something about that.
Don't be afraid if you don't understand all these options yet.
I will give you some information later where you can find out exactly what they do.
So let's create it with science equals 0.10 at location
123.
And there you have a really tiny sphere.
Let's create a bit bigger one at a different location.
It's that simple really.
We've already found quite a bit of information in blenders user
interface but there's also blenders api documentation which you can find
right here in blender
point in api reference.
It opens a browser for you with the information
and you can use that copy paste trick again.
So let's see shift a mesh UV sphere control. C
then I go to the browser
and hit paste in the quick search,
click on the first link
and there you have the explanation of what is what
another good source of information is the python standard library.
So what have we seen so far?
Well we know that computers are stupid and just do
the commands one x one that we give them.
We've seen how to use the python console and how to create objects,
remove objects and modify existing ones.
We've seen what we can do with
just copying information from blender shows our interface
and have pointed you to a few sources of information where you can find more stuff.
So in the next video we will look at names
and objects because typing be pied data that objects,
that cube.
That's something that's something that's something becomes really boring.
After a while
see you in the next video.