0% found this document useful (0 votes)
11K views29 pages

Python Scripting in Blender For Humans by Christopher Topalian

Python is fun to use in Blender! We can customize everything! We can remake interfaces, customize tools, make our own tools and so much more!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11K views29 pages

Python Scripting in Blender For Humans by Christopher Topalian

Python is fun to use in Blender! We can customize everything! We can remake interfaces, customize tools, make our own tools and so much more!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Title Page: The title page displaying the name of the book and author information.
  • Dedication: A dedication page offering thanks and acknowledgement.
  • Screen Layout - Scripting: Instructions on configuring the Blender interface for scripting, showing steps to access the scripting layout.
  • Console Setup: Guides on how to toggle and use the console for displaying script results and error messages in Blender.
  • Creating a New Script: Explains how to create a new Python script in Blender and start writing code.
  • Writing First Code: Instructions for writing a simple Python print statement and running the script in Blender.
  • Console Result: Shows the output of the Python code executed in the Blender console.
  • Saving a Script: Details on renaming Python scripts and saving them within Blender.
  • Info Window: Demonstrates how to use the Info Window for extra script details and outputs within Blender.
  • Objects in Scene: Gives an overview of how to display all objects present in the Blender scene using Python code.
  • Scene Objects Result: Presents the actual list of objects generated by the script in Blender's console.
  • Understanding Scene Objects: Illustrates the types of objects in a simple Blender scene and explains their attributes.
  • Referencing Objects by Name: Covers how to reference a Blender scene object by name within a Python script.
  • Object Location by Name: Teaches how to retrieve the location of an object in the Blender scene using Python scripting.
  • Object Scale by Name: Details obtaining the scale of a Blender scene object through Python code.
  • Object Rotation by Name: Describes retrieving the Euler rotation of a scene object in Blender with a script.
  • Scene Naming: Explains how to retrieve the name of the current Blender scene using Python scripting.
  • Setting Object Location: Shows how to set the location of a Blender object programmatically with a script.
  • Acknowledgements: Acknowledgments and additional information about the author and educational outreach.

Christopher Topalian

Python
Scripting
in

[Link]
Blender
for
Humans
by
Christopher Topalian
Copyright 2021
All Rights Reserved

College of Scripting Music & Science [Link]


Christopher Topalian

DEDICATED
TO
GOD THE FATHER

College of Scripting Music & Science [Link]


Christopher Topalian
Screen Layout - Scripting

Left
Click
Here Left Click
Scripting

[Link]
College of Scripting Music & Science

We open the application Blender.


We then click on the Layout button.
We choose Scripting as the layout.
This makes it easy for us to script.
College of Scripting Music & Science [Link]
Christopher Topalian

Console
Left Click
Window

[Link]
Left Click
Toggle System Console
College of Scripting Music & Science

College of Scripting Music & Science

We use this Console to show


Results of our Scripting and
any Error Messages

College of Scripting Music & Science [Link]


Christopher Topalian
New Script

[Link]
College of Scripting Music & Science

Left Click
New

We make a New Script by clicking the


button that is named New.
This creates an new script.
We can then type our code into it.
College of Scripting Music & Science [Link]
Christopher Topalian
We Type in our first Code

To Hold
Type Make Ctrl +

[Link]
this code Bigger Mouse
Font Wheel
Forwards
College of Scripting Music & Science
Run Script

Left Click
Run Script

College of Scripting Music & Science


Next Page Shows the Result ->

We type the code


print('Hi Everyone')
and then we press the Run Script button.
College of Scripting Music & Science [Link]
Christopher Topalian
Result of Our Script in Console

College of Scripting Music & Science

[Link]
Result of our Python Code
SHOWN in the
Blender System CONSOLE

We use this Console to show


results of our scripting and to
show any error messages.

In Blender, the Window Menu


allows us to
Toggle System Console.

College of Scripting Music & Science [Link]


Christopher Topalian
Rename ourScript & Save As

College of Scripting Music & Science


2
3

[Link]
Left Click
Text Left Click
Save As

1 Type
ourScript

We Type in the name section ourScript


We then choose the Text Menu.
We choose Save As.
Now our Script is saved in blender.
College of Scripting Music & Science [Link]
Christopher Topalian
Info Window

Info window
College of Scripting Music & Science

[Link]
Put Mouse On Horizontal Line
Hold Left Mouse Button
and Drag Downwards

College of Scripting Music & Science

We show the Info Window by dragging


the Horizontal Line downward.
This window provides useful data.
College of Scripting Music & Science [Link]
Christopher Topalian
Show All OBJECTS in Scene

College of Scripting Music & Science

[Link]
Type this
code

Left Click Run Script


Run Script

Result Shown in Console Window

College of Scripting Music & Science [Link]


Christopher Topalian
Show All OBJECTS in Scene

import bpy

ourList = list([Link])

[Link]
print(ourList)

Result
[[Link]['Camera'],
[Link]['Cube'],
[Link]['Lamp']]
We have 3 objects in our Scene

College of Scripting Music & Science [Link]


Christopher Topalian
We Have 3 Objects in Our Scene

College of Scripting Music & Science

Lamp
Cube
name
Cube

[Link]
Camera

Location Scale
Rotation

Our Blender Scene is very simple.


It has a Camera,
a Lamp
and a Cube.
We can name these objects
anything we want!
Notice, that Objects have
Location, Rotation and Scale
College of Scripting Music & Science [Link]
Christopher Topalian
Refer to Object by NAME
import bpy
ourObject = [Link]['Cube']
print(ourObject)

[Link]
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Cube"

College of Scripting Music & Science [Link]


Christopher Topalian
Refer to Object by NAME
import bpy
ourObject = [Link]['Lamp']
print(ourObject)

[Link]
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Lamp"

College of Scripting Music & Science [Link]


Christopher Topalian
Refer to Object by NAME
import bpy
ourObject = [Link]['Camera']
print(ourObject)

[Link]
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Camera"

College of Scripting Music & Science [Link]


Christopher Topalian
Get Location of Object by Name

[Link]
College of Scripting Music & Science

College of Scripting Music & Science [Link]


Christopher Topalian
Get Location of Object by Name
import bpy
ourObject = [Link]['Cube']
print([Link])

[Link]
Returns the Vector Location
of Our Cube, which is located
at <0.0000, 0.0000, 0.0000>

College of Scripting Music & Science [Link]


Christopher Topalian
Hovering Over Elements for Info
College of Scripting Music & Science

Hover the
Mouse Arrow

[Link]
Here

Location of the object.


Python: [Link]
[Link]["Cube"].location[0]
Hover Tips
Hover the Mouse Arrow over buttons and
other elements in Blender to be shown
the Python scripting reference.
College of Scripting Music & Science [Link]
Christopher Topalian
Get Scale of Object by Name

[Link]
College of Scripting Music & Science

Returns the Vector Scale


of Our Cube, which is
<0.0000, 0.0000, 0.0000>
College of Scripting Music & Science [Link]
Christopher Topalian
Get Scale of Object by Name
import bpy
ourObject = [Link]['Cube']
print([Link])

[Link]
Returns the Vector Scale
of Our Cube, which is
<0.0000, 0.0000, 0.0000>

College of Scripting Music & Science [Link]


Christopher Topalian
Hovering Over Elements for Info

Hover

[Link]
Mouse Arrow
Here

Scaling of the Object.


Python: [Link]
[Link]["Cube"].scale[0]

Hover Tips Show Python Reference

College of Scripting Music & Science [Link]


Christopher Topalian
Get Rotation of Object by Name

[Link]
College of Scripting Music & Science

Returns the Euler Rotation


of Our Cube, which is
<Euler (x=0.0000, y=0.0000,
z=0.0000), order='XYZ'>

College of Scripting Music & Science [Link]


Christopher Topalian
Get Rotation of Object by Name
import bpy
ourObject = [Link]['Cube']
print(ourObject.rotation_euler)

[Link]
Returns the Euler Rotation
of Our Cube, which is
<Euler (x=0.0000, y=0.0000,
z=0.0000), order='XYZ'>

College of Scripting Music & Science [Link]


Christopher Topalian
Hovering Over Elements for Info

Hover
Mouse

[Link]
Arrow
Here

Rotation in Eulers.
Radians: 0.000000
Python: Object.rotation_euler
[Link]["Cube"].rotation_euler[0]

Hover Tips Show Python Reference

College of Scripting Music & Science [Link]


Christopher Topalian
Get Name of Current Scene

College of Scripting Music & Science

[Link]
Returns the Scene name
of Our Current Scene,
which is named Scene

College of Scripting Music & Science [Link]


Christopher Topalian
Get Name of Current Scene
import bpy
ourScene = [Link]['Scene'].name
print(ourScene)

[Link]
Returns the Scene name
of Our Current Scene,
which is Scene

College of Scripting Music & Science [Link]


Christopher Topalian
Hovering Over Elements for Info

[Link]
Hover
Mouse Arrow
Here

Scene data-block, consisting in objects &


defining time and render related settings.
Value: Scene
Python: [Link]
[Link]["Scene"].name

Hover Tips Show Python Reference


Remember, that Blender shows us the
Python reference when we hover our
mouse arrow over an element.

College of Scripting Music & Science [Link]


Christopher Topalian
Set Location of Object
import bpy

ourObject = [Link]['Cube']
[Link] = (5.0, 0.0, 0.0)

[Link]
print([Link])

Moves object to vector location.


This script moves the object named
Cube to the location specified,
X position of 5.0
Y position of 0.0
Z position of 0.0
College of Scripting Music & Science [Link]
Christopher Topalian

DEDICATED
TO
GOD THE FATHER
Presented by the
College of Scripting
Music & Science
We have taught over 2 million people
how to program computers, for free,
since March of 2007!
[Link]/ScriptingCollege
[Link]/ChristopherTopalian
[Link]
[Link]
Christopher Topalian Copyright 2007-2021
All Rights Reserved. All content here is protected.

College of Scripting Music & Science [Link]

You might also like