Support Blender Core Development with a monthly contribution.
The creators who share. Access production content and knowledge from the Open Movies.
Latest news and updates on Blender development.
Join the community and help with design, development, docs and more.
A platform to collect and display the Blender Benchmark results.
Documentation on Blender's features, tools and API.
The yearly event that brings together the Blender community in one place.
Download the latest Blender version, or try the beta!
You can join Blender Studio for €9.90/month and get access to all of our training & film content instantly!
Login Join Blender StudioVideos
16th August 2017
info License: CC-BYPublished by
Many tasks can be described as doing stuff on a list of things. For example, going through all objects and selecting those that meet a certain description.
for ... in ... :
print()
if ... :
Slides are only visible to Blender Cloud susbcribers
51 Comments
Join to comment publicly.
Silke Fischer-Imsieke
15th January 2021 - 14:55
now it's bpy.ops.mesh.primitive_monkey_add(size=0.2, location=(x, y, 1)) instead of radius
Roelant Rijs
10th May 2018 - 16:44
For those playing along at home: try changing the value of 1 for the Z location of the monkeys to X^Y. This (partial) tetrix or Sierpinski tetrahedron might enthuse the easily distracted. That's the bitwise XOR operator in action by the way, for powers you want something like X**Y. The result looks a lot less spectacular though.
Jeremy Bot
4th August 2018 - 04:42
@roelant.rijs: That's pretty neat. Worth mentioning to others that it failed on mine the first time around, as it didn't like capital versions of X and Y, so should be x^y instead of X^Y
Sybren A. Stüvel
6th August 2018 - 11:01
@Jeremy Bot: For variable names (and function names, class names, and pretty much all other names), following PEP-8 is a good idea. That way your styling is consistent with what most other Python programmers are doing. It'll also make it easier for them to help you!
David mcsween
31st August 2017 - 08:10
Hmmm, should have rendered your shirts with filmic :D #Joking
David mcsween
6th September 2017 - 09:38
If anyone has trouble finding the object(id) listing in the manual, as described in the video, it is here https://docs.blender.org/api/blender_python_api_master/bpy.types.Object.html
Sybren A. Stüvel
6th September 2017 - 21:59
@3pointedit: Thanks, I've added it to the video description.
David mcsween
7th September 2017 - 06:09
Perhaps this should be renamed "If you want to make 9 monkeys first create 600 monkeys!" :D
VJ Galaxy
12th March 2019 - 16:28
For some reason version 2.8 beta does not include the .hide method. :(
Sybren A. Stüvel
12th March 2019 - 17:30
*@alejandropineroamerio* Blender 2.8 changes quite a few things, check the release notes for more info.
VJ Galaxy
12th March 2019 - 23:48
*@Sybren A. Stüvel* Thanks
Collins Okech Swah
30th August 2019 - 18:02
When I try to run the script, it keeps giving me an error that 'continue not in loop' Why is that?
Sybren A. Stüvel
24th September 2019 - 16:21
*@Collins Okech Swah* Come poke us at #blender-cloud -- it's hard to debug such things here.
Henk Kok
11th January 2020 - 11:28
Thank you for including Slides and Video for this presentation
I often return here to check something out, and the slides allow for fantastic speed to check the content at a glance. And the video is equally good because I can get a solid exploration of the concepts.
Aleksey Novykov
12th April 2020 - 12:08
Hello, Seems like the code from these tutorials is not supported in 2.8 Is it planned to update the content?
Sybren A. Stüvel
16th April 2020 - 13:16
*@Aleksey Novykov* Check the 'Blender 2.80' link at the top of the page, there I explain what's different between the versions, and how to update the code. I'm not planning on re-recording the existing chapters, as 99.99% will be the same anyway. New chapters are all made for the latest Blender version.
Jack Kimberley
18th June 2020 - 11:49
the ctrl + space doesn't seem to work. Maybe something changed for 2.9? It seems to be TAB in console but in the text editor it just has text previously typed. Is it meant to work in text editor? Because trying to find the syntax in console then copying it into text editor is becoming very tedious.
Sybren A. Stüvel
18th June 2020 - 21:09
*@Jack Kimberley* It's not supposed to work in the text editor. It's a text editor, not a super-smart auto-completing IDE ;-)
David Maslin
24th January 2021 - 06:44
Why is this not updated for 2.9?
Sybren A. Stüvel
16th February 2021 - 12:09
@David Maslin Because it takes a lot of work, and personally I'd rather spend that on improving Blender itself. The release notes on the wiki are always a good source for keeping track of changes.
Jim Conrad
15th April 2021 - 01:56
@Sybren A. Stüvel Understandable. Re-editing the videos would be quite a bit of work, but maybe updating the slides would be a reasonable compromise. From the perspective of someone who just paid for a Blender Cloud subscription solely for the purpose of learning from these videos, it's a bit disheartening to know that these won't be updated.
Luis Felipe Peredo Noguez
12th February 2021 - 20:13
The course is being interesting so far, but its not as friendly as it could be for non mathematically intuitive persons, this is to say to an artist that has low mathematical intuitive understanding some of the more math infused explanations will just go over ones head, the part where I started to not quite get things is when idx was introduced, I understood that the x = idx % 25 and y = idx // 25 are lines that distribute the 600 monkeys on the x and y axis at a constant spacing, but how that work mathematically I don't quite get, and the explanation of how that works was done in just a couple of fairly heavy mathematically infused lines of dialogue, the result is that for people like me the explanation did not served its purpose, but a person that has a more mathematically inclined mind tho, what you said must be alright tho. Another thing I think would be nice to have is to to have the files you initial start the project with available so the student does not has to guess as what the setup is on the lesson, its not a critical thing, as you can infer that watching the video, but it would be a nice thing to have, maybe I missed that tho, if you can download the project files for each lesson somewhere let me know.
Sybren A. Stüvel
16th February 2021 - 12:02
@Luis Felipe Peredo Noguez Thanks for the feedback.
The
%
operator computes the remainder after division. For example13 % 3
would evaluate to1
, because13 = 4 * 3 + 1
, i.e. after dividing13
by3
you are left with a remainder of1
.The
//
operator is an integer division, so13 // 3
would evaluate to4
. Using a single slash would perform a normal division, so13 / 3
evaluates to4.333333333333
.Peter Cook
23rd April 2021 - 04:56
Okay some of the code does not work in 2.92. I hade to change the line
Peter Cook
23rd April 2021 - 05:16
@Peter Cook I had to change the line "if not ob.hide" to "if ob.hide_set(False)"
Salvador Garcia Luque
8th May 2021 - 08:31
Hello I'm having trouble running the scripts in blender 2.92. I'm sure the api has changed and i was wondering in the examples what changed. The line I'm having rpoblems with is bpy.ops.mesh.primitive_monkey_add(radius=0.2, location=(x, y, 1))
Sybren A. Stüvel
28th May 2021 - 10:29
@Salvador Garcia Luque That's right, sometimes Blender changes the API a little. I want to write a page with upgrade notes, but in the mean time you can check the Release Notes; the Python API section should list any API changes.
Salvador Garcia Luque
7th June 2021 - 00:40
@Sybren A. Stüvel thank you, Sybren. :) :thumbs_up:
Sigvaldas
9th May 2021 - 12:24
Code changed a bit for Blender 2.8 so this is my solution. Hope it will help someone who is stuck. import bpy
bpy.ops.object.select_all(False) for allObjects in bpy.context.scene.objects: if allObjects.hide_set(True): continue if 'Cube' not in allObjects.name: continue allObjects.select_set(True) allObjects.hide_set(False)
Smartdog
2nd August 2021 - 05:40
I believe Blender 3.0 code for 600 tiny monkey in rows of 25 is a little different from the video.
3.0: "size" is used instead of "radius"
https://docs.blender.org/api/current/bpy.ops.mesh.html?highlight=primitive_monkey_add#bpy.ops.mesh.primitive_monkey_add
import bpy
for idx in range(600):
x = idx % 25
y = idx // 25
bpy.ops.mesh.primitive_monkey_add(size=0.2, location=(x, y, 1))
Sybren A. Stüvel
5th October 2021 - 18:57
@Smartdog yes, that's as documented in https://cloud.blender.org/training/scripting-for-artists/pages/blender-versions/ ;-)
Steven Goodman
6th August 2021 - 21:30
Try it with the z location of the monkeys set to x*y.
David mcsween
6th September 2017 - 09:55
Quick question, when doing the monkey script, Blender would run the script while I was typing in the 'location' part? I did not hit run script. Is that a bug or a feature? Fun side effect, I was able to delete all the monkeys by using the select hidden script (modified).
Sybren A. Stüvel
6th September 2017 - 22:00
@3pointedit: That depends on where you type it. The Python Console executes your code line-by-line as you type it, the Text Editor only runs it if you press the "Run Script" button (or press the key combo that's bound to it).
David mcsween
7th September 2017 - 05:12
@sybren: ah haaa, I had an old code snippet in the python console from your earlier example, it must have been executing somehow. Thanks
David mcsween
7th September 2017 - 05:21
@sybren: Hmm, its still auto-executing the script when I paste operators in? I have cleared the python console as well.
David mcsween
7th September 2017 - 05:54
@sybren: Ok, I made a clean .blend project and copied the script across and now it doesn't autorun. I'm not sure what happened to the other file to make it do that. Should I post the broken .blend file for someone to investigate?
Sybren A. Stüvel
7th September 2017 - 11:52
@3pointedit: if you suspect it's a bug, file a report at developer.b.o.
Vincent Lamy
8th September 2017 - 08:06
@3pointedit: have you checked "Live Edit" in Properties panel ?
Sybren A. Stüvel
8th September 2017 - 17:55
Please take discussions like this to Stack Exchange, and keep comments here directly related to the Scripting for Artists video.
David mcsween
11th September 2017 - 04:57
@vinc3r: Oh wow, thanks. I never even realized what this did. I must have turned it on by accident when applying the other display settings.
Diego Cerda
15th December 2017 - 04:14
On tutorial 3 and have no clue on what i'm doing. Is there like a lesson for the slow on here? lol
Sybren A. Stüvel
19th December 2017 - 11:19
@diegoisthename: What is your personal motivation to follow the tutorials? And can you point at where you started losing your clue? I'd like to get you back on track, helps to have some context.
Brandon Bien
18th March 2018 - 00:47
My understanding of this is a bit flawed, I'm having trouble wrapping my head around how you can put anything in place of "ob" and it will return all of the objects in bpy.context.selected_objects. Are you assigning each object to "ob" with bpy.context.selected_objects?
Sybren A. Stüvel
21st March 2018 - 14:44
@Brandon Bien: I need some context to really answer this. Can you tell me the timecode of the video of the bit you're referring to?
acoval.05
18th June 2020 - 06:10
*@Brandon Bien* This is the way you itterate through a list , I think you might find it helpful seing a more thorough explanation of how python or any other programming language works. For example for i in list: print(i) Where "i" can be swapped for anything that will represent each position in a list [1,2 ,3 ,4 ,5]
Eric Imboden
28th December 2018 - 17:21
Hello,
The code described in this video is not compatible with Blender 2.8. I've tried to make it work but there's something I am not doing right.
I hope the rest of the videos will work fine.
I'm not ok with the last two lines and there's something I'm not understanding in this page. Below is what I did (indentation not working)
Any help will be welcome.
Sybren A. Stüvel
29th December 2018 - 15:33
*@Eric Imboden* You're right, the entire series is aimed at Blender 2.79, which is still the current release of Blender. You can find more info on how things are done in 2.80 in its pending release notes.
Simon Velthuis
12th September 2019 - 09:47
*@Eric Imbodenl* This helped me:
https://cloud.blender.org/p/scripting-for-artists/blender-28
i've got it working like this:
David Maslin
24th January 2021 - 07:05
@Simon Velthuis Thanks ;)
Simon Velthuis
6th April 2021 - 14:10
@David Maslin You're very welcome ;)