Home Artists Posts Import Register

Content

OHyeah! Getting into some python!

Obviously there are lots of tutorials out there by far more knowledgeable people- this isn't an "introduction to python" or anything like that (I tend to recommend Curtis Holt's videos, but there are tons of options out there), because this effectively skips most of that bit and kinda jumps straight into, "yeah but can I do stuff", which always helps me learn, personally, because I need to feel like I'm making progress or I'll get frustrated and give up :P .

Mostly I'm just super jazzed to finally feel like I have my head around this a little bit (I've been poking at python for years without ever actually doing anything 'useful'), and I'm hoping this video might potentially bring anyone else who was in the same position as me along for the ride.

Obvious huge thanks to Nathan Vegdahl, who's been a ever-genial fount of pythonic wisdom, and without whom I don't think I would have gotten this far.

Again, there are tons of resources scattered around online, and I should definitely link to the blender python API, which is a huge source of documentation for the way blender interacts with python.

OH ALSO here's the python script from the video. I added a lot of in-line documentation to sort of re-explain what goes where. 

Files

Make a simple Blender Addon/Hotkey/Button with Python

OHyeah! Obviously there are lots of tutorials out there by far more knowledgeable people- this isn't an "introduction to python" or anything like that (I tend to recommend Curtis Holt's videos, but there are tons of options out there), because this effectively skips most of that bit and kinda jumps straight into, "yeah but can I do stuff", which always helps me learn, personally, because I need to feel like I'm making progress or I'll get frustrated and give up :P . Mostly I'm just super jazzed to finally feel like I have my head around this a little bit (I've been poking at python for years without ever actually doing anything 'useful'), and I'm hoping this video might potentially bring anyone else who was in the same position as me along for the ride. Obvious huge thanks to Nathan Vegdahl, who's been a ever-genial fount of pythonic wisdom, and without whom I don't think I would have gotten this far. Again, there are tons of resources scattered around online, and I should definitely link to the blender python API, which is a huge source of documentation for the way blender interacts with python. https://docs.blender.org/api/current/ OH ALSO here's the python script from the video. I added a lot of in-line documentation to sort of re-explain what goes where. https://drive.google.com/file/d/1VjCYTuzEsm-psvU4OjzyMOjgnhS3yioq/view?usp=sharing

Comments

Anonymous

Wow thanks! I was waiting for this, I'm into coding and had no idea where to start in Blender.

Anonymous

I haven't watched the video yet, but I can tell just by looking at the thumbnail, it's gonna be great!! haha I also see that it's about python which is something I've been very interested in learning, I'm very glad you're talking about this :D.

Anonymous

Definitely check out the “Serpens Visual Scripting” addon for blender. It’s an Addon that makes Addons. But you can use trusty nodes to build your addons and it’s awesome. Thought be everything I now know about scripting

IanHubert

I really hope it helps! It's the video that I (as a person who mostly knows nothing about coding) wish I'd had, but I have no idea how useful it'll be for someone who's already familiar!

Roy

Recently been showing covid symptoms, I have been binge watching your videos and to post 2 videos in the same time frame and I couldn't be happier, You're the best Ian!

Jostein Lie Svalheim

I wish i had a super awesome programmer living in my backyard church, because i got my bi-monthly urge to learn coding again and i sure could use the help!

IanHubert

Oh that's cool to hear! Nathan and I were talking yesterday and one of us said, "an addon that makes addons?" and Nathan got this thoughtful look in his eye- I'll definitely check it out!

IanHubert

Oh no!! Stay safe, Roy!! Hope it isn't too unpleasant! Very happy to hear the videos are a help :D

Anonymous

What beer is that? I have to taste the "ian hubert is drinking that"-beer :D Or atleast imagine that its a "Ian Hubert offered me this beer"-Beer

IanHubert

Ahahaha they're Fat Tires- I like em, but they're also very much, "yup, that's a beer".

Anonymous

Uggghhhh for ages I’ve been trying to work out why models were freaking out and showing the wrongs faces? It was as simple as “image back face”! Ha. Thank you

IanHubert

YES! I have no idea why that's the default! It's a relatively new issue too, I believe (I did all of these "just use 'image as plane' and start extruding!" based tutorials, and suddenly doing that gives SUPER weird results, so I feel bad for anyone currently trying to do the tutorial and being confused!) Nathan thinks it's a legitimate bug- I might try filing it if I can figure out what's going on a bit better.

Anonymous

I loved using Blender to teach python to high school students because the data structure is so accessible, this was a treat to watch!

Anonymous

Send my regards to Nathan, Ian, I'm big fans of his rigging tutorial...Anyway, any plan to invite Nathan for Co-Host in future python tutoral, watching both of you would be hillarious :)

Anonymous

I've started to shake and sweat.... code is... not... easy.... I like easy.... (I'm actually at work and playing this video in the background. So not really paying attention... I'm sure it'll be fine... Nurse!!! My pills!!

Anonymous

When I started learning Blender scripting, the first thing I did was go through the Python tutorial. It's very useful for basic programming and learning how python normally does things, so the Blender parts aren't quite so intimidating.

Anonymous

I've been programming for over 20 years, but I've never learnt python, and I found this super useful! I keep thinking about writing code for python but I keep tripping up on the first step of what you said - I don't know what the things are that I don't know! But now I know how to do some really useful things, thank you!

Anonymous

↑ Same - python shot in the arm/vaccination

Anonymous

Very interesting (and funny) watching when non-programmer is talking about programming in Python. "Python loves lists" (LOL). I was using Python occasionally over 20 years, since 1.5 version. Nice vid. You also don't use passed context, but that's OK. You will figure it out. After couple of years. :-P

Anonymous

I just noticed, watching through this again, that you put the hotkey registration code in a weird place. Putting it in the class (as you did) kind of "accidentally" works. But it's weird. Normally you'd want to put it in the register() function. But that's my fault, for not catching it when I reviewed the video before you posted!

Anonymous

Unrelatedly: hi Paul!!! It's been forever since I've seen you! If you're ever in the Seattle area again, let's hang out!

Anonymous

you are doing good as a coder myself i approve

Anonymous

Ian and I did actually go over the passed context etc., but Ian (I think smartly) decided to leave that out of this initial tutorial, since everything works by just copy/pasting from the command history in most cases anyway. Keeps everything simpler for beginners.

Anonymous

For the 96000th time in my life, I'm thinking I should get seriously into addon coding. I've used some Python in the past, so it feels a bit of a waste not to use it for Blender. I loved the future Ian and Nathan commenting on past Ian's progress 😅

Anonymous

hahaha i know the feeling! It's always like "This time, im gonna grab my head around it and actually learn to use it"... And yet here am.. still only been able to watch youtube videos and not reeaally wanting to get into it :D

Anonymous

Ian, I think you summarized a big challenge of programming: you need to learn how to ask specifically what you're looking for. It sounds silly, but asking the question properly usually brings up some Stack Overflow responses. It's a life-safer.

Anonymous

you seem to have read my mind

Anonymous

Before line 22, you can add a condition that checks if the object has a material assigned. only in the case that's true, it will execute the next line.

Anonymous

Ah this reminds me, I wrote a python add-on that automatically imports a high quality piece of footage alongside a proxy version in Blender for doing viewport compositing, so that scenes don't run at -3 frames a second when you have a bunch of footage in a scene... If anyone has interest give me a shout. Great video as always Ian!

Anonymous

Hey Ian! It's good to see your interest in scripting! That was the last skill missed you. Enjoy it! I guarantee you that the next natural step will go through "Geometry Node", you'll see ;)

Anonymous

I'm loving the fact that Ian finds Python weird, but thinks that Blender is totally logical.... 🤣🤣🤣

Anonymous

Quick tip: If you bracket that line that clears the "Show Backface" flag with a "try:" "except Exception:" then you choose to ignore the error, rather than display it. Note also that, if you don't, no lines below "line 22" will get executed in the event that the error occurs.

Anonymous

So, the hotkey will get set every time the script is run?

IanHubert

Ahahaha that's a good point- yeah I guess if I'd been using Python for 16 years Blender would definitely be the weird one. AND AH! Thanks for the tip and the link!! There's a bit I should have included in the video where Nathan and I talked about how that'd be a perfect next step (either ignoring the warning, or actually just adding a material)- I'll give it a shot! Actually, I want to make a "chrome" button that makes any object chrome. If it has a material already, it'll delete it and and replace it with a chrome one. I think's doable! Although I'll have to learn some "if" stuff, and possibly the way materials are stored relative to objects?? I'm sure it'll be more difficult than I think :P

Anonymous

Informative video :), also stumbled upon this addon called 'Serpens' wich is basicly node based Python scripting to some extend.. or atleast simplefyes the process a bit. Also it has a built in compiler so you can just compile addons inside blender and export them (atleast im pretty shure you can) :D, if all the code lines are too confuzing you might wanna check that out.. hav'nt tryed it my selfe but looked verry prommising. Have a Good day, much love!

Anonymous

I've not looked at the the Blender Python API until today. Your video was great inspiration... ;) Playing around I worked out the code below, which does most of what you want...

Anonymous

import bpy MATERIAL_NAME = "Chrome" def setup_chrome(): chrome = bpy.data.materials.new(MATERIAL_NAME) chrome.use_nodes = True node = chrome.node_tree.nodes["Principled BSDF"] node.inputs["Base Color"].default_value = (0.6, 0.6, 0.6, 1) node.inputs["Roughness"].default_value = 0.01 node.inputs["Specular"].default_value = 1 node.inputs["Metallic"].default_value = 1 try: bpy.data.materials[MATERIAL_NAME] except KeyError: setup_chrome() bpy.context.object.active_material = bpy.data.materials[MATERIAL_NAME]

IanHubert

Oh cool! Does it generate the proxy, or mostly just make the process of switching between the two a bit easier?

IanHubert

VERY excited to get more into geometry nodes! Especially for cities and random vehicles and such- could be SO useful for self-generative type stuff!

Anonymous

Python is not that difficult to learn and it's an amazing language. Of course, in this case it's more difficult because you have to link it in Blender. But for someone like you that is a master in Blender, learning this will give you even more tools to play :)

Anonymous

Both! Made a quick video here that shows the functionality, saved me a good chunk of time, but it's a pretty specific workflow. If anyone here wants it, just give me a shout and I'll send the script and some basic documentation! https://www.youtube.com/watch?v=h5AgspdBi3M

Anonymous

Yeah! You'll see that Geometry Nodes is just like coding within objects data and it's really intersesting for a tone of things. I've just setup a sprit system that only display instanced objects in the camera fov and based on a near/far range from the cam location. Usefull for optimizing vegetation in my 1000m² landscape!

Anonymous

Thanks for this video Ian! It almost makes me want to try making python scripts myself... almost! :-)

Anonymous

python makes blender even more magical

Anonymous

Hey! For anyone interested, I kinda dove in and wrote an addon for Blender (with someone that knows a lot more python than me) that can send you an email notification when your render is done. You can download it (for free) from here: https://github.com/DeadSplicer/Blender-Render-Notification-Submit-Credentials

Anonymous

I use the first camera shake tutorial so...so much....soooo much.

Anonymous

The same confusion comes the first when u are learning Blender (or any other *complicated* program), like , sometimes u need a tutorial for the tutorial and so on xdd.

Anonymous

This was such an easy to follow intro I was able to put together a simple addon with a few functions that really speed up my sculpting workflow. Huge productivity boost... never would've happened without this!