New answers tagged

0 votes

Blender python doesn't recognize installed packages when ran in Blender

Same issue on Windows. Solution: Ensure administrator permissions when using pip
user avatar
  • 161
0 votes

An array of 3D arrows (python in Blender)

Here's something I wrote that I think you might find useful. v0, v1, and v2 are three corners of a square and I used nested for loops to create an array of arrows. To create the arrows themselves, I ...
user avatar
  • 372
0 votes

Shortcut to Rotate 60 degree via Script

Shortcuts, of course, are set up in the keymap in Preferences. Creating a short cut requires an operator: typing the shortcut key invokes the operator. In this instance, there isn't a specific ...
user avatar
2 votes
Accepted

GLSL: 2D space transform matrix of Custom Shader

If you draw a rectangle with the built-in shaders, they all use ModelViewProjectionMatrix. The documentation states: "...They all read the uniform mat4 ModelViewProjectionMatrix, which can be ...
user avatar
  • 6,163
0 votes

Need help with script that loops through a collection and bakes objects

to Marty Fouts point, I was not setting the bpy.context.active_object. This was the solution for blender 2.8+ ...
user avatar
  • 163
0 votes

How can I speed up this bake script I wrote?

https://devtalk.blender.org/t/why-is-texture-baking-so-mind-meltingly-slow/5653 This post actually solved my problem. I was focused on the script being the issue, where the slow render was a result of ...
user avatar
  • 163
4 votes
Accepted

Create a Disjointed Curve Using a Python Script

Just turn the script you have into a function. Then you can reuse it as many times as you want and feed it different coordinates each time. If you use an external variable to keep track of how many ...
user avatar
  • 1,676
0 votes
Accepted

Select/Unselect collections through python script

I think it's easier to disable and enable collections on render. For example: ...
user avatar
  • 22.7k
1 vote
Accepted

change a word in armature bones names with a script

Rename bones ...
user avatar
  • 2,077
0 votes

Exporting Mesh + Material does not work with error message "NO NODES!"

I am no expert, but perhaps Blender cannot export materials as defined in my code. My workaround is to apply colors using textures instead of generating the colors through Blender. So basically, I ...
user avatar
3 votes

If there is any way in Blender I can use a mathematical formula to control particle density?

If you are referring to particle emitter you can get a close approximation directly or run a script for greater accuracy by utilizing the curve guide force. Create a sphere object and add an emmision ...
user avatar
  • 1,841
0 votes

If there is any way in Blender I can use a mathematical formula to control particle density?

1) Enable Extra Objects Addon 2) Add Mesh > Math Function Use Geometry Nodes to display points
user avatar
  • 2,077
7 votes

Set collection color in outliner with Python

The color tag can be set through collection.color_tag if collection is an object of type ...
user avatar
  • 23.4k
1 vote

How to delete a keyframe of an object at a specific frame with python?

Baking an animation causes all of the actions of that animation to be converted to a single action. In the process of doing so it replaces every Nth step in the animation's in-between calculation ...
user avatar
0 votes

Renaming Animation Channels with a Script for dummies

My brain was too smooth for the pyscript above (I'm sure it works but in the 30 seconds I attempted to type it in I got confused) so I found out how to do it the caveman way. In the image above the ...
user avatar
1 vote
Accepted

How to delete a keyframe of an object at a specific frame with python?

object.keyframe_delete("location", frame=1) will delete location keyframes at frame 1. But if you want to delete all keyframes you can do like this: ...
user avatar
  • 22.7k
0 votes

OSL script node : detect if two object collides and output a bool

It's my first experience with OSL, so I can't say if this code has no bugs, but at first look it works as it should. I used source from Secrop's comment and adapted just as he advised. ...
user avatar
  • 111
0 votes

Batch set orientation of local axes on multyple objects?

I see that a lot of objects have the same rotation. So that you can edit them at once. Make a transform orientation based on selected edge or face Activate transform only origins: Then select all ...
user avatar
  • 22.7k
1 vote

Python: Check data path is valid of driver variable

By Gorgious's idea, use eval to test the path, any answers can success are welcome. ...
user avatar
  • 2,077
1 vote

Python: Check data path is valid of driver variable

I think you're confusing yourself by trying to insert a function that returns true or false. Python already makes this stuff easy, You don't have to do "if tar.data_path == '' or vice versa. In ...
user avatar
  • 1,676
0 votes

Blender Script - How would you copy all modifier settings like Collisions from an active object to other selected objects?

Copy collision settings use dir(x) to get list of attribute ...
user avatar
  • 2,077
0 votes

Calling an addon's Operator from Python - wm_operator_invoke: invalid operator call

@Chris Watts Doesn't seem to be valid in 2022 (or am I wrong?). Created this small addon and calling bpy.ops.object.myaddonoperator('EXEC_DEFAULT') returns an error:...
user avatar
3 votes
Accepted

Is there any reason anyone would prefer appending/removing external parts over excluding/including collections in an object generator?

Yes, there is a potentially valid reason: the second approach results in a much larger blend file while the first approach allows the blend file to remain relatively small. Whether it's the reason for ...
user avatar
0 votes

Replace image in blender using script

Change Image Texture image ...
user avatar
  • 2,077
0 votes

Replace image in blender using script

I suggest you try to use a video texture. if you encode with ffmpeg video and choose the webm encoder and setup trasnparency in the film render setting, the video can have transparency.
user avatar
  • 131
3 votes
Accepted

Apply copy transform constraint using script

This code is an example of how to do that, but I've left out three settings because I didn't know if the default was enough ...
user avatar
1 vote

Offset an animation fcurve in python?

In response to your comment to your question, here's an example, using an operator override, to move every fcurve 3 units on the X axis: ...
user avatar
4 votes
Accepted

How to generate images of model components using python?

Your question is too broad for a complete answer in one place. Below I outline the solution and suggest areas of research for specific steps. Please try to put together a complete script on your own ...
user avatar
1 vote

Offset an animation fcurve in python?

Move All keyframe_points for a object ...
user avatar
  • 2,077
1 vote

How to delete point from spline

Replace your last line with ...
user avatar
2 votes

How to delete point from spline

Delete bezier curve vertice ...
user avatar
  • 2,077
1 vote

How to put a keyframe on render visibility through python on blender

This line will set a keyframe on visibility for an object called "Torus" at keyframe 1: ...
user avatar
2 votes

How do I grab the header in an area?

I find the manual's Window System Introduction a helpful means of discovering the names of the various parts of the Blender Window. These part names carry over mostly intact to the Python ...
user avatar
1 vote

How do I grab the header in an area?

Area is the whole editor. The header area is defined in a special header class. There is usually just one for the header area in each editor. And that class is where you place your content of the ...
user avatar
  • 1,890
3 votes
Accepted

How can I transform my coffee cup into a torus as seen on wikipidea?

Use Shape Keys to animate the vertices 1) Make mug You can make the mug by run my script ...
user avatar
  • 2,077
3 votes
Accepted

Unable to toggle multiple snapping options at once using blender pyhton

You're setting all values to True so there isn't any toggling going on. I have 3 remarks : Operators should return a set indicating their state at the end of ...
user avatar
  • 25.2k
2 votes

Applying gradual transformation to multiple objects

Using Geometry Nodes on Blenver v3.1.2 Node tree
user avatar
3 votes
Accepted

Applying gradual transformation to multiple objects

linear Cubic Rotate effect ...
user avatar
  • 2,077
0 votes

How to set up driver via python script between Custom Properties of objects?

Replace add_driver(ob, camera, prop_name1, prop_name1, -1) With ...
user avatar
  • 25.2k
2 votes
Accepted

How to control enviroment texture with collection visibility?

If you can settle for the first collection that is enabled for rendering, then you need code that looks something like this: ...
user avatar
2 votes
Accepted

How to code min and max values for custom property to selected object?

You can use the bpy.types.Object.id_properties_ui method that acts as a manager to change the custom properties settings on the fly. ...
user avatar
  • 25.2k
1 vote
Accepted

Align Active Object to Curve based on Eyedropper

Avoid placing heavy loads code in draw() The code in draw() function will excuite Frequently. ...
user avatar
  • 2,077
3 votes
Accepted

Does Blender text editor not support custom module importing?

EDIT: Hopefully clearer answer in response to comments. The short answer is 'No, you can't do that'. The long answer The reason this works in VSC is that Python has a system variable called ...
user avatar
0 votes

How do I make a bone active using Python?

bpy.context.object.data.bones.active = bpy.data.objects["rig"].pose.bones["spine_fk.003"].bone This works in Blender 2.93 LTS, and a call to <...
user avatar
0 votes

Copying drivers and transform_space attribute

You need change variable type first. ...
user avatar
  • 2,077
1 vote

Import data to blender from CSV

Yes. Here's an example that would read your data and create text blocks for each line. You may want to read the manual entry for [Text][1] for more details on editing the content of a text block. <...
user avatar
2 votes
Accepted

how can ı remove(delete) empty lines in my script or let say text with codes? is it possible

First check index of the lines you want to delete ...
user avatar
  • 2,077
1 vote

Get the source path of the assets in Asset Browser using Python

Such a precise and elegant solution by Gorgious... I would have taken tons of lines of code to do the exact same thing (I am not a coder, as you might've guessed...) Posting my final code with a few ...
user avatar
  • 53
5 votes
Accepted

Attach float attributes for each vertex of mesh

Do this after you create the verts (with from_pydata) but before you call mesh.update() ...
user avatar
  • 6,812
3 votes
Accepted

Material slot renaming - Only rename slot if it is in use?

There is a Python idiom for this: if thing: do something That means 'if this thing has a value other than None then do ...
user avatar

Top 50 recent answers are included