Blender Studio
  • Films
  • Projects
  • Training
  • Characters
  • Tools
  • Blog
  • Join
  • BLENDER.ORG

    • Download

      Get the latest Blender, older versions, or experimental builds.

    • What's New

      Stay up-to-date with the new features in the latest Blender releases.

    LEARNING & RESOURCES

    • Blender Studio

      Access production assets and knowledge from the open movies.

    • Manual

      Documentation on the usage and features in Blender.

    DEVELOPMENT

    • Developers Blog

      Latest development updates, by Blender developers.

    • Documentation

      Guidelines, release notes and development docs.

    • Benchmark

      A platform to collect and share results of the Blender Benchmark.

    • Blender Conference

      The yearly event that brings the community together.

    DONATE

    • Development Fund

      Support core development with a monthly contribution.

    • One-time Donations

      Perform a single donation with more payment options available.

Training Highlights
Stylized Rendering with Brushstrokes
Geometry Nodes from Scratch
Procedural Shading Fundamentals
Stylized Character Workflow

Training types
Course Documentation Production Lesson Workshop

Training categories
Animation Geometry Nodes Lighting Rendering Rigging Shading
Film Highlights
Wing It!
2023
Charge
2022
Sprite Fright
2021
Spring
2019
Project Highlights
Project DogWalk
Interactive
Gold
Showcase
BCON24 Identity
Showcase
Fighting with Grease Pencil
Article
Course
Scripting for Artists
Blender Versions
Videos
  1. 01

    Introduction & copy-pasting

    Free
  2. 02

    Names & Objects

  3. 03

    Stuff on Lists

  4. 04

    Data Types

  5. 05

    Collections: Mass-Rename of Objects

  6. 06

    Blender Collections

    Free
  7. 07

    For vs. While

    Free
  8. 08

    Your Own Operator

    Free
  9. 09

    From Script to Add-on

    Free
  10. 10

    User Interfaces

    Free
  11. 11

    Custom Properties

    Free
  12. 12

    Asset Linking

    Free
  13. 13

    Roast my Add-on

    Free
  14. 14

    The Roast of Nature Clicker

    Free
  15. 15

    Modal Operators

    Free
  16. 16

    Readability & Understandability

Tech
  1. 01

    Updating F-Curves

  2. 02

    Render 10,000 OBJ files

  3. 03

    Mass-Rename Bones & Vertex Groups

  4. 04

    Rendering from 'all' angles

Login to view this content

Join Blender Studio for just €11.50/month and get instant access to all of our training and film assets!

Login Join Blender Studio
Sybren Stüvel
Sybren Stüvel Author
License CC-BY
Report Problem
Videos

Stuff on Lists

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.

  • Looping with for ... in ... :
  • Calling functions like print()
  • Conditionally run code with if ... :
  • Creating 600 tiny monkeys
  • Work with your own lists

Links from the video

  • Learn how to open a terminal at the Blender Manual.
  • bpy.types.Object in the API documentation.

The Slides

Slides are only visible to Blender Cloud susbcribers

Join to leave a comment.

52 comments
Nathan Vasil
Nathan Vasil
March 4th, 2023

Following along in 3.41 (it's still very good, thank you!)  For those  having problems like Eric Imboden, it appears that "select" has been given get/set functions; for deselecting an object, invoking "object.select_set(False)" seems to be how it's done now.  (At least, it does what I expect; but if I was an expert in bpy, I wouldn't be watching this series :P)

Steven Goodman
Steven Goodman
Aug. 6th, 2021

Try it with the z location of the monkeys set to x*y.

Smartdog
Smartdog
Aug. 2nd, 2021

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 Stüvel
Sybren Stüvel
Oct. 5th, 2021

@Smartdog yes, that's as documented in https://cloud.blender.org/training/scripting-for-artists/pages/blender-versions/ ;-)

Sigvaldas
Sigvaldas
May 9th, 2021

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)

Salvador Garcia Luque
Salvador Garcia Luque
May 8th, 2021

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 Stüvel
Sybren Stüvel
May 28th, 2021

@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
Salvador Garcia Luque
June 7th, 2021

@Sybren A. Stüvel thank you, Sybren. :) :thumbs_up:

Peter Cook
Peter Cook
April 23rd, 2021

Okay some of the code does not work in 2.92. I hade to change the line

Peter Cook
Peter Cook
April 23rd, 2021

@Peter Cook I had to change the line  "if not ob.hide" to "if ob.hide_set(False)"

Luis Felipe Peredo Noguez
Luis Felipe Peredo Noguez
Feb. 12th, 2021

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 Stüvel
Sybren Stüvel
Feb. 16th, 2021

@Luis Felipe Peredo Noguez Thanks for the feedback.

The % operator computes the remainder after division. For example 13 % 3 would evaluate to 1, because 13 = 4 * 3 + 1, i.e. after dividing 13 by 3 you are left with a remainder of 1.

The // operator is an integer division, so 13 // 3 would evaluate to 4. Using a single slash would perform a normal division, so 13 / 3 evaluates to 4.333333333333.

David Maslin
David Maslin
Jan. 24th, 2021

Why is this not updated for 2.9?

Sybren Stüvel
Sybren Stüvel
Feb. 16th, 2021

@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
Jim Conrad
April 15th, 2021

@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.

Silke Fischer-Imsieke
Silke Fischer-Imsieke
Jan. 15th, 2021

now it's  bpy.ops.mesh.primitive_monkey_add(size=0.2, location=(x, y, 1)) instead of radius

Jack Kimberley
Jack Kimberley
June 18th, 2020

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 Stüvel
Sybren Stüvel
June 18th, 2020

*@Jack Kimberley* It's not supposed to work in the text editor. It's a text editor, not a super-smart auto-completing IDE ;-)

Aleksey Novykov
Aleksey Novykov
April 12th, 2020

Hello, Seems like the code from these tutorials is not supported in 2.8 Is it planned to update the content?

Sybren Stüvel
Sybren Stüvel
April 16th, 2020

*@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.

Henk Kok
Henk Kok
Jan. 11th, 2020

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.

Collins Okech Swah
Collins Okech Swah
Aug. 30th, 2019

When I try to run the script, it keeps giving me an error that 'continue not in loop' Why is that?

Sybren Stüvel
Sybren Stüvel
Sept. 24th, 2019

*@Collins Okech Swah* Come poke us at #blender-cloud -- it's hard to debug such things here.

VJ Galaxy
VJ Galaxy
March 12th, 2019

For some reason version 2.8 beta does not include the .hide method. :(

Sybren Stüvel
Sybren Stüvel
March 12th, 2019

*@alejandropineroamerio* Blender 2.8 changes quite a few things, check the release notes for more info.

VJ Galaxy
VJ Galaxy
March 12th, 2019

*@Sybren A. Stüvel* Thanks

Eric Imboden
Eric Imboden
Dec. 28th, 2018

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.

import bpy
bpy.ops.object.select_all(action='DESELECT')
for ob in bpy.context.scene.objects:
    if ob.hide_viewport:
        continue

    if '.00' not in ob.name:
        continue

    ob.select_set(True)
    ob.hide_viewport = False
Sybren Stüvel
Sybren Stüvel
Dec. 29th, 2018

*@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
Simon Velthuis
Sept. 12th, 2019

*@Eric Imbodenl* This helped me:

https://cloud.blender.org/p/scripting-for-artists/blender-28

i've got it working like this:

import bpy
# select all hidden objects that have '.00' in their name.

# deselect everything
bpy.ops.object.select_all(action='DESELECT')

for ob in bpy.context.scene.objects:
    if not  ob.hide_get(): #new in 2.8
        continue # done iterating loop

    if '.00' not in ob.name:
        continue

    ob.hide_set(False) #new in 2.8
    # section has to be at the end, otherwise no selsction active
    ob.select_set(True) #new in 2.8
David Maslin
David Maslin
Jan. 24th, 2021

@Simon Velthuis Thanks ;)

Simon Velthuis
Simon Velthuis
April 6th, 2021

@David Maslin You're very welcome ;)

Roelant Rijs
Roelant Rijs
May 10th, 2018

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
Jeremy Bot
Aug. 4th, 2018

@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

Show more replies
Sybren Stüvel
Sybren Stüvel
Aug. 6th, 2018

@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!

Brandon Bien
Brandon Bien
March 18th, 2018

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 Stüvel
Sybren Stüvel
March 21st, 2018

@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?

Show more replies
acoval.05
acoval.05
June 18th, 2020

*@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]

Diego Cerda
Diego Cerda
Dec. 15th, 2017

On tutorial 3 and have no clue on what i'm doing. Is there like a lesson for the slow on here? lol

Sybren Stüvel
Sybren Stüvel
Dec. 19th, 2017

@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.

David mcsween
David mcsween
Sept. 7th, 2017

Perhaps this should be renamed "If you want to make 9 monkeys first create 600 monkeys!" :D

David mcsween
David mcsween
Sept. 6th, 2017

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 Stüvel
Sybren Stüvel
Sept. 6th, 2017

@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).

Show more replies
David mcsween
David mcsween
Sept. 11th, 2017

@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.

Sybren Stüvel
Sybren Stüvel
Sept. 8th, 2017

Please take discussions like this to Stack Exchange, and keep comments here directly related to the Scripting for Artists video.

Vincent Lamy
Vincent Lamy
Sept. 8th, 2017

@3pointedit: have you checked "Live Edit" in Properties panel ? live edit

Sybren Stüvel
Sybren Stüvel
Sept. 7th, 2017

@3pointedit: if you suspect it's a bug, file a report at developer.b.o.

David mcsween
David mcsween
Sept. 7th, 2017

@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?

David mcsween
David mcsween
Sept. 7th, 2017

@sybren: Hmm, its still auto-executing the script when I paste operators in? I have cleared the python console as well.

David mcsween
David mcsween
Sept. 7th, 2017

@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
David mcsween
Sept. 6th, 2017

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 Stüvel
Sybren Stüvel
Sept. 6th, 2017

@3pointedit: Thanks, I've added it to the video description.

David mcsween
David mcsween
Aug. 31st, 2017

Hmmm, should have rendered your shirts with filmic :D #Joking

Films Projects Training Blog Blender Studio for Teams
Pipeline and Tools
  • CloudRig
  • Blender Kitsu
  • Brushstroke Tools Add-on
  • Blender Studio Extensions
Characters
  • Mikassa
  • Whale
  • Ballan Wrasse
  • Snow
Studio
  • Terms & Conditions
  • Privacy Policy
  • Contact
  • Remixing Music
Blender Studio

The creators who share.

Artistic freedom starts with Blender The Free and Open Source 3D Creation Suite