Very nice. You could continue this great script by making it more idiomatic Python. For example, rather than reassigning from and to node variables (only in python is this ever considered acceptable code 😱) simply define a function that takes the from/to nodes and output/input names to connect as parameters. This is a two-birds refactoring: readability and reusability. You can use the same technique with the x-coordinate of the nodes. Hide the increment in a function, call it each time and just assign each new return value when you create the node. Then you can also encapsulate that within a new_node(…) function that takes a node name and calls the increment. I’m coming at this as a Python programmer learning Blender scripting. We’ll meet in the middle! Again, awesome tutorial.
Is there a way to stop a script from running when it doesn't work without shutting down Blender? Right now, I choose kill terminal in VS Code and it stops processing the script of course, but in doing so it shuts down Blender as well. Also, why are my scripts becoming read only where I can't edit them?
I can't think of a great solution for this. > Also, why are my scripts becoming read only where I can't edit them? What version of the extension are you running? I think this was fixed in [0.0.22] - 2024-09-04 "Blender: Run Script" will no longer open read-only file when hitting debug point (#142)" github.com/JacquesLucke/blender_vscode/blob/master/CHANGELOG.md If you are running version [0.0.22] or higher Please ask to reopen github.com/JacquesLucke/blender_vscode/issues/140
Thank you for sharing. Please no background Sounds/music. I am not an native english speaker and it makes it hard to follow, your sometimes really fast, speechpattern 😖
Now scripts created on ChatGPT can get errors. I’ve created a Blender add-on that automates the process of having GPT generate code, running it in the text editor, and pasting any errors back into GPT. It also automates finding code examples to give it. You can provide it with any add-on or file as an example. For people who write Blender Python scripts, this is a game-changing tool. Is there a way I could get you to do a video on it? Or maybe I could send you a copy to test-it’s really robust, with over twenty thousand lines of code.
Now scripts created on ChatGPT can get errors. I’ve created a Blender add-on that automates the process of having GPT generate code, running it in the text editor, and pasting any errors back into GPT. It also automates finding code examples to give it. You can provide it with any add-on or file as an example. For people who write Blender Python scripts, this is a game-changing tool. Is there a way I could get you to do a video on it? Or maybe I could send you a copy to test-it’s really robust, with over twenty thousand lines of code.
Thanks for the good and useful videos. I'm pretty new to Blender programming. I'm using homebrew to install a lot of useful s/w. The python3 - m pip install fake-bpy-module forces to use either brew or pipx. However, either of those works. Can you add the homebrew and pipx way in you video? I would help a lot.
Hello Victor, I thought I saw that it was possible in some way to do the opposite. I mean install blender as a python module. Wouldn't that be more advantageous? If possible, would you consider making a video to explain how to do it? THANKS
@@ced9302 depends on your use case. But yes, you can install Blender as a Python module; I use it for unit testing. But it's effectively running Blender headless, so not everything is enabled (say, simulating user input). If you want Blender's UI, then you'd be better off with Blender as an app.
Yeah, I have a video on this in the works. You can find the bpy module here pypi.org/project/bpy/ It is great for doing bulk processing of assets. I would say you would iterate on your script with the blender UI and then once everything is working you would use this bpy module installed from pip. I think it would be hard to iterate on a script without the UI, unless you have years for experience with bpy.
Great video! Thanks for sharing that, neat tip. And just so users know, they don't have to install Python or pip themselves. It's already included with Blender. The path on Windows is "C:\Program Files\Blender Foundation\Blender 4.2\4.2\python\bin\python.exe". So you can just do "python.exe -m pip" instead of just "pip" while in that folder (or use the full file path).
the problem am facin is how to separate system python of blender python. or how to change interpreter without getting conflicts. I start getting this issues just recently on win 11
This is amazing. No idea if you're still maintaining this but would you have an example that could import a list of .stl files (like you do .blend files) and use them as the source objects for renders instead of linking .blend files?
figured out how to convert my .stl to .blend first ... so that solves that problem. Now working on trying to make things rotate on multiple axis in the same render.
What Blender version are you using? You might need to make it into an extension. I need to make an updated video of this If you are using 4.2 you can checkout the changes done to add-on here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-QrDt1_Bn670.htmlsi=bE-eHfz3A2ZiA09V
I have a question: I am building an addon in which I will make use of some Python wheels, but one of these wheels needs OpenImageIO and numpy to work. I have done some research and found out that Blender has OpenImageIO and numpy installed as Python modules, if I decide to exclude OpenImageIO and numpy wheels from my addon, could the wheel that depends on them to work have problems to run? That is, would my addon detect and work fine with those modules that come by default in Blender?
Great question! You should be fine using the OpenImageIO and numpy that come with Blender. You would only need to worry about this if your add-on needed a particular version of OpenImageIO or numpy.
Hi! total python noob here. How do I create a script that will add drivers to shape keys for me? I'm trying to control shape keys with empties, but due to the number it would be tedious to add the drivers manually every time (I'm using CC4 characters, which come with a bunch of shape keys, but no way to control them easily unless you buy Iclone). I can't seem to find an answer on google or reddit.
Try this example gist.github.com/CGArtPython/d446d51e08f4d6bd277134173d1311e2 This Blender Python script adds 5 empty objects to the current scene and then assigns drivers to each empty. The drivers are set to control the X location of each empty based on the X location of the next empty in the list, multiplied by 0.5.
Here is a very simple add-on. The __init__.py file contains the following code: import bpy class OBJECT_OT_add_cube(bpy.types.Operator): bl_idname = "object.add_cube" bl_label = "Add Cube" bl_options = {'REGISTER', 'UNDO'} def execute(self, context): bpy.ops.mesh.primitive_cube_add() return {'FINISHED'} class VIEW3D_PT_simple_panel(bpy.types.Panel): bl_label = "Simple Cube Panel" bl_idname = "VIEW3D_PT_simple_panel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Simple Cube Addon' def draw(self, context): layout = self.layout layout.operator("object.add_cube") def register(): bpy.utils.register_class(OBJECT_OT_add_cube) bpy.utils.register_class(VIEW3D_PT_simple_panel) def unregister(): bpy.utils.unregister_class(OBJECT_OT_add_cube) bpy.utils.unregister_class(VIEW3D_PT_simple_panel) if __name__ == "__main__": register() And here is the manifest file: schema_version = "1.0.0" id = "simple_cube_addon" name = "Simple Cube Addon" version = "1.0.0" tagline = "Adds a panel that spawns a cube" maintainer = "Your Name <your.email@example.com>" type = "add-on" tags = ["Object"] blender_version_min = "4.2.0" license = ["SPDX:GPL-2.0-or-later"] Why doesn't it launch in VS Code, but works fine when zipped and installed in Blender?
I am able to run your code from VSCode looks like the issue is with `_name_ ` here is the explanation ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--qq64ReRZhU.html
Can you give a little information on the mesh_size:props.FloatProperty() block. Is this a python definition convention or blender? Is it a key:value pair? I am maybe at an intermediate level of python and I've not seen definitions like this so far.
This is a great question! This actually uses type annotation syntax. Type annotations are evaluated for classes, so this is basically a function that registers some information with Blender and returns a type peps.python.org/pep-0526/#runtime-effects-of-type-annotations blender.stackexchange.com/a/246159