Intro to Blender using python

Intro to Blender using python 









I'm not an artist. I have been learning unreal since nearly 8 months and part of it is creating assets in blender.







For those who do not know, blender is a free open source 3d creation software. It does a lot from rigging to texturing to creating pbr materials to creating 3d objects.

U can create really complex stuff in blender using code (python). U can even create procedural cities and why not, even planets! I have been using python to automate asset creation in blender for my unreal 4 projects. Here's a little intro that can get you going.

First off this is not an intro to blender. I suggest you look for intros on YouTube(there is a ridiculous amount of really good quality)

The first thing you should do is see all the python code happening in the background from the console. Its hidden pretty well.




Go to the menu bar and drag it down with your cursor.


This is where all the python code will be seen once you do anything in blender.

To get a blank screen , press a and delete then ok.



Once you have a blank screen as shown above , its time to start the python part.



In the upper right corner of the 3d window you should see this :


Drag it to created two 3d windows!




Then on the lower left of the second 3d window you just created click on 

A menu will pop up 



Click on Text Editor 

The second window has to look like this now:





















































On the lower middle part of this window click on + NEW

And you now have a text editor to type in your python code in blender!


You should know that most of the interface and addons of blender are written in python.

It's a mix of c , c++ and python . Right now we are interested only with python.

Everything you do in the interface generates python code.
For example 

1. click on the 3d window
2. type shift+a
3. choose Mesh then cube to add a cube to the scene


Now now have a cube in the scene 


But this was done using the interface not python code.
Let's do the same thing but in python.
Delete everything in the scene first by pressing "a" (once or twice , selected objects are highlighted in orange) then delete.

On to the code now .

To use python in blender you have to import the blender module (bpy) into the python code so 


Before we added a cube via the interface and deleted it. Since the interface is in python , you will see these commands in the console . The command for adding a cube is there!


The command that starts with  bpy.ops.mesh.primitive_cube..........
That's the one that added the cube.
Right click on it to select it ( will be highlighted in blue) 



Then CONTROL+V to copy the line 

Now paste that directly in the text editor on the second line 



If you run this right now , it will generate a cube!

To run this you have 3 options:
1. Press ALT+P
2.Click on Text > run script
3. Click on the run script button 



And you just created a cube in 3d using python code.

Next time will show how to modify the parameters of the cube and create pillars.
The aim is to show how to create a procedural city so keep in touch  for that!
I will also be uploading tutorials on unreal 4 soon ( blueprint + c++ code )






I created the island above in unreal. The dragon is a free asset. Eventually the series of tutorials will lead to doing stuff like that.












Comments