bpy | blender python scripts | Addon library
kandi X-RAY | bpy Summary
kandi X-RAY | bpy Summary
blender python scripts
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Projects points onto points
- Update a vertex store
- Progress the current progress
- Log a message
- Start rendering
- Render the object
- Check if the plugin is ready
- Intersect the point cloud
- Evaluate points on the point cloud
- Compute point cloud visualization
- Create a new scene
- Export point cloud visualization
- Make the PSC instance
- Activate object
- Preload sequence numbers
- Remove color from point cloud
- Generate from mesh
- Load a PLY file
- Compute the modified matrix
- Execute the program
- Parse the file header
- Render point cloud visualization
- Calculate the rotation matrix
- Apply the remap
- Calculate the matrices of the quaternion
- Render the point cloud
bpy Key Features
bpy Examples and Code Snippets
Community Discussions
Trending Discussions on bpy
QUESTION
I would like to be able to instance an object/objects and give it a random color (creating a unique name for materials seems to be necessary for some kind of blender internal reason).
When I do it by hand and copy the commands out of the Info Context Menu for one cube it seems to work. But as soon as I try to put a simple script together it does not. For the following code I am getting an AttributeError
since apparently the attribute name
does not exist.
ANSWER
Answered 2022-Mar-10 at 01:43I belive this does the desired action
it was quite tricky as like described in here you need to set up input and output shaders and link it up correctly
QUESTION
How do I automatically execute a python script after Blender has fully loaded?
ContextMy script generates a scene based on a seed. I want to creat a couple thousand images but since Blender leaks memory after a hundred generations or so everything becomes significantly slower and eventually crashes. I want to migitate the problem by creating only x images per session and completely restart Blender after each session.
ProblemIf I load the blend file manually and click the play button in the script editor, everything works as expected. When I try to call the script after startup, it crashes in add_curve_spirals.py
line 184, since context.space_data
is None
.
Since manually starting the script works fine, the problem is, that Blender is in some sort of wrong state. Starting it with or without GUI (--background
) does not affect this.
blender myfile.blend --python myscript.py
executes the script before the context is fully ready and thus produces the error.- Using a handler to delay execution (
bpy.app.handlers.load_post
) calls my script after completely loading the file but still the context is not ready and it produces the error. - Setting the script in Blender to auto execute on startup (Text/Register) also produces the error.
- Using sockets, as suggested here, to send command to Blender at a later time. The server script, that is waiting for incomming commands, blocks Blender during startup and prevents it from fully loading, hence the effect is the same as executing the script directly.
- Using timed events (
bpy.app.timers.register(render_fun, first_interval=10)
.
These are all the ways that I found to automatically execute a script. In every case the script seems to be executed too early / in the wrong state and all fail in the same way.
I want to stress that the script is not the issue here. Even if I could work around the particular line, many similar problems might follow and I don't want to rewrite my whole script. So what is the best way to automatically invoke it in the right state?
...ANSWER
Answered 2022-Feb-04 at 10:55It turns out, that the problem was the execution context. This became clear after invoking the timed event manually, e.g. after the scene was loaded completely the timed event was still executed in a wrong context.
Since the crash happened in the add_curve_spirals
addon, the solution was to provide a context override the the operator invokation. The rest of my script was not equally sensitive to the context and worked just fine.
It was not clear to me, how exactly I should override the context, but this works for now (collected from other parts of the internet, so I don't understand all details):
QUESTION
thank you in advance
I am trying to start a Celery Worker to accept WebConnections usng Channels - but when my worker starts it cannot seem to find channels. When I pip list channels is installed
settings.py has channels
...ANSWER
Answered 2021-Nov-09 at 15:39QUESTION
I am trying to generate a large (> 1 million) of cubic meshes that I then will have to reprocess in Blender.
Currently, I do that by actually generating the cubes in Blender using their Python API, like so:
...ANSWER
Answered 2021-Nov-04 at 08:30primitive_add_cube
is an operator, which causes a scene update. The more objects you add, the more has be to updated after every addition. So it becomes exponentially slower.
You should avoid that by using the low-level API. If you want to add the same mesh (cube) again and again, simply copy the object. If you don’t be this to be a linked duplicate, also copy the mesh data:
QUESTION
I have a colmap export of the camera pose file which named "images.txt".
...ANSWER
Answered 2021-Oct-15 at 13:38After loading R and T try this and use quaternions for camera direction.
QUESTION
import bpy
f = open("C:/Users/xxx/Desktop/CODING.txt", 'w')
for i in bpy.context.selected_objects:
result = print(i.name.split(".")[1])
result = str(result)
f.write(result)
f.close()
...ANSWER
Answered 2021-Oct-05 at 07:51print
returns None
. Just use result = i.name.split(".")[1]
instead. And no need to convert it to string afterward. So this would suffice:
QUESTION
>>> a = bpy.context.selected_objects
>>> a[:2]
[bpy.data.objects['Sphere.001'], bpy.data.objects['Sphere.010']]
>>>
...ANSWER
Answered 2021-Oct-04 at 14:26Is this what you want?
QUESTION
I want to show a list of ICameraInfo
in a ComboBox.
ICameraInfo is an interface that give you many infos of a camera. You get each info using indexer.
In my case I want to display the parameter ICameraInfo[CameraInfoKey.FriendlyName]
in the ComboBox (CameraInfoKey is a static class).
In ViewModel:
...ANSWER
Answered 2021-Aug-14 at 21:09If ICameraInfo
does not have FriendlyName
property that you want and you must get the actual value from an indexer property, I don't think that DisplayMemberPath
is the way for you to go. Instead, you should probably layout the ItemTemplate
for your ComboBox
and in it, have a TextBlock that pulls the string value. You could even use a converter for this if necessary. For example, something like this:
QUESTION
I tried to render an object (.obj & .ply - both doesn't work) using bpy(version 2.93.1
), but they were grey (without color), despite that they had vertex color.
ANSWER
Answered 2021-Jul-18 at 12:24I found the solution! If you paste
QUESTION
Given a Blender (ver 2.9) model that is made up of separate objects, each of which is a triangle, I have a script which exports them to a custom format that includes the position, euler rotation and vertices of each triangle.
Because my target program rotates the triangle using the specified object euler angles, I need to 'flatten' the vertices of each triangle into just XY coordinates, as if the triangle was 2D.
This is my first Blender script and first Python script, so it's very basic without any error-checking. Assume that my objects are definitely all triangles :) It currently exports the vertices 'as-is' in 3D.
...ANSWER
Answered 2021-Jul-17 at 18:17I'm not quite sure what your goal is but to "flatten" the vertices sounds like a projection operation where you need to transform the vertex positions so Z equals zero. For that you could calculate the face orientation of the triangle and rotate the triangle vertices by the negative of that. But then it is also unclear what the significance of the local offset is around which that rotation would takes place. You could try to elaborate on the result you want to achieve, the source data you're working with or your attempts on it so far since the solution might as well be just ignoring the Z value of the triangle vertices when exporting if they're already provided aligned flat to the plane of the X and Y axis.
Adding answers from the comments below:
1: To rotate the triangle around its center point P where P is the average position of the 3 vertices (V0+V1+V2)/3 and the rotation R is derived from the face normal which is calculated with the dot product of the vectors V1-V0 and V2-V0 as elaborated here https://stackoverflow.com/a/1516330/15786521 the vertices need to moved by the negative of P, rotated by the negative of R and then moved back by P or in matrix operations where V is a vertex position:
V' = V x M(-P) x M(-R) x M(P)
The problem though is that rotations don't commute, meaning that the outcome of rotating around the X and then by the Y axis is not the same as rotating it around Y and then by X. In your case rotating around the yaw, then pitch, and ignoring the roll might work but I can not tell which way would best suit you since the resulting roll of the triangle would differ if you rotated by the pitch first for instance.
2: If you simply want to map your triangle on a texture or the like where only the proportions matter and the 3d orientation is irrelevant since the goal seems to neutralize/flatten it then simply get the dot product and distances of the vectors V1-V0 and V2-V0 and construct your 2D representation of the triangle from that.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bpy
You can use bpy like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page