Join Blender Studio for just €11.50/month and get instant access to all of our training and film assets!
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
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)
Try it with the z location of the monkeys set to x*y.
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"
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))
@Smartdog yes, that's as documented in https://cloud.blender.org/training/scripting-for-artists/pages/blender-versions/ ;-)
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)
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))
@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.
@Sybren A. Stüvel thank you, Sybren. :) :thumbs_up:
Okay some of the code does not work in 2.92. I hade to change the line
@Peter Cook I had to change the line "if not ob.hide" to "if ob.hide_set(False)"
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.
@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
.
Why is this not updated for 2.9?
@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.
@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.
now it's bpy.ops.mesh.primitive_monkey_add(size=0.2, location=(x, y, 1)) instead of radius
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.
*@Jack Kimberley* It's not supposed to work in the text editor. It's a text editor, not a super-smart auto-completing IDE ;-)
Hello, Seems like the code from these tutorials is not supported in 2.8 Is it planned to update the content?
*@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.
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.
When I try to run the script, it keeps giving me an error that 'continue not in loop' Why is that?
*@Collins Okech Swah* Come poke us at #blender-cloud -- it's hard to debug such things here.
For some reason version 2.8 beta does not include the .hide method. :(
*@alejandropineroamerio* Blender 2.8 changes quite a few things, check the release notes for more info.
*@Sybren A. Stüvel* Thanks
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
*@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.
*@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
@Simon Velthuis Thanks ;)
@David Maslin You're very welcome ;)
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.
@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
@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!
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?
@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?
*@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]
On tutorial 3 and have no clue on what i'm doing. Is there like a lesson for the slow on here? lol
@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.
Perhaps this should be renamed "If you want to make 9 monkeys first create 600 monkeys!" :D
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).
@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).
@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.
Please take discussions like this to Stack Exchange, and keep comments here directly related to the Scripting for Artists video.
@3pointedit: have you checked "Live Edit" in Properties panel ?
@3pointedit: if you suspect it's a bug, file a report at developer.b.o.
@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: Hmm, its still auto-executing the script when I paste operators in? I have cleared the python console as well.
@sybren: ah haaa, I had an old code snippet in the python console from your earlier example, it must have been executing somehow. Thanks
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
@3pointedit: Thanks, I've added it to the video description.
Hmmm, should have rendered your shirts with filmic :D #Joking
Join to leave a comment.