Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6K views

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
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6K views

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
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Christopher Topalian

Python
Scripting
in

COLLEGEOFSCRIPTING.WEEBLY.COM
Blender
for
Humans
by
Christopher Topalian
Copyright 2021
All Rights Reserved

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian

DEDICATED
TO
GOD THE FATHER

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Screen Layout - Scripting

Left
Click
Here Left Click
Scripting

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian

Console
Left Click
Window

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com


Christopher Topalian
New Script

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
We Type in our first Code

To Hold
Type Make Ctrl +

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
Result of Our Script in Console

College of Scripting Music & Science

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com


Christopher Topalian
Rename ourScript & Save As

College of Scripting Music & Science


2
3

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
Info Window

Info window
College of Scripting Music & Science

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
Show All OBJECTS in Scene

College of Scripting Music & Science

COLLEGEOFSCRIPTING.WEEBLY.COM
Type this
code

Left Click Run Script


Run Script

Result Shown in Console Window

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Show All OBJECTS in Scene

import bpy

ourList = list(bpy.data.objects)

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourList)

Result
[bpy.data.objects['Camera'],
bpy.data.objects['Cube'],
bpy.data.objects['Lamp']]
We have 3 objects in our Scene

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
We Have 3 Objects in Our Scene

College of Scripting Music & Science

Lamp
Cube
name
Cube

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
Refer to Object by NAME
import bpy
ourObject = bpy.data.objects['Cube']
print(ourObject)

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Cube"

College of Scripting Music & Science CollegeOfScripting.weebly.com


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

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Lamp"

College of Scripting Music & Science CollegeOfScripting.weebly.com


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

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the TYPE, which is a
bpy_struct, and that it is
an Object named "Camera"

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Get Location of Object by Name

COLLEGEOFSCRIPTING.WEEBLY.COM
College of Scripting Music & Science

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Get Location of Object by Name
import bpy
ourObject = bpy.data.objects['Cube']
print(ourObject.location)

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the Vector Location
of Our Cube, which is located
at <0.0000, 0.0000, 0.0000>

College of Scripting Music & Science CollegeOfScripting.weebly.com


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

Hover the
Mouse Arrow

COLLEGEOFSCRIPTING.WEEBLY.COM
Here

Location of the object.


Python: Object.location
bpy.data.objects["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 CollegeOfScripting.weebly.com
Christopher Topalian
Get Scale of Object by Name

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com
Christopher Topalian
Get Scale of Object by Name
import bpy
ourObject = bpy.data.objects['Cube']
print(ourObject.scale)

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the Vector Scale
of Our Cube, which is
<0.0000, 0.0000, 0.0000>

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Hovering Over Elements for Info

Hover

COLLEGEOFSCRIPTING.WEEBLY.COM
Mouse Arrow
Here

Scaling of the Object.


Python: Object.scale
bpy.data.objeccts["Cube"].scale[0]

Hover Tips Show Python Reference

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Get Rotation of Object by Name

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com


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

COLLEGEOFSCRIPTING.WEEBLY.COM
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 CollegeOfScripting.weebly.com


Christopher Topalian
Hovering Over Elements for Info

Hover
Mouse

COLLEGEOFSCRIPTING.WEEBLY.COM
Arrow
Here

Rotation in Eulers.
Radians: 0.000000
Python: Object.rotation_euler
bpy.data.objects["Cube"].rotation_euler[0]

Hover Tips Show Python Reference

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Get Name of Current Scene

College of Scripting Music & Science

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the Scene name
of Our Current Scene,
which is named Scene

College of Scripting Music & Science CollegeOfScripting.weebly.com


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

COLLEGEOFSCRIPTING.WEEBLY.COM
Returns the Scene name
of Our Current Scene,
which is Scene

College of Scripting Music & Science CollegeOfScripting.weebly.com


Christopher Topalian
Hovering Over Elements for Info

COLLEGEOFSCRIPTING.WEEBLY.COM
Hover
Mouse Arrow
Here

Scene data-block, consisting in objects &


defining time and render related settings.
Value: Scene
Python: Scene.name
bpy.data.scenes["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 CollegeOfScripting.weebly.com


Christopher Topalian
Set Location of Object
import bpy

ourObject = bpy.data.objects['Cube']
ourObject.location = (5.0, 0.0, 0.0)

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourObject.location)

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 CollegeOfScripting.weebly.com
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!
www.youtube.com/ScriptingCollege
www.github.com/ChristopherTopalian
www.CollegeOfScripting.weebly.com
www.CollegeOfScripting.wordpress.com
Christopher Topalian Copyright 2007-2021
All Rights Reserved. All content here is protected.

College of Scripting Music & Science CollegeOfScripting.weebly.com

You might also like