Questions tagged [scripting]

Questions concerning scripting in Blender using the Python programming language. Also use this tag for questions about scripting in OSL (Open Shading Language).

Filter by
Sorted by
Tagged with
10
votes
2answers
14k views

Import 3D XML in Blender or convert it with another tool

I would like to find a way to import 3D XML (zipped file with XML Data and textures) files into Blender or find a workaround without using 3dvia, or AutoDesk to convert it. I know there is a python ...
8
votes
2answers
8k views

Get center of geometry of an object

With Object > Transform > Origin to Geometry, an object's origin is moved to its geometry's center. How can I get this center in script? I don't want to move its origin, I just need to get its center....
6
votes
2answers
5k views

Change active collection

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code: ...
10
votes
4answers
2k views

How can I create a mathematically correct arc/circular segment?

Given 3 vertices, or a chord and height, how can I create a mathematically correct arc/circular segment with an even distribution of vertices while controlling for the number of vertices. I ...
9
votes
1answer
5k views

Python Render Specific Frames

I'm new to blender scripting and with the api change in 2.56 I'm having difficulty finding relevant information. I'm trying to render 8 non-consecutive single frames to pngs. They are the same scene ...
2
votes
2answers
2k views

How to draw shapes in the node editor with python bgl

I want to draw a diagram using shapes such as triangles and squares in the node editor. How can I do this?
11
votes
2answers
9k views

Add modifier to selected and another to active object

I am trying to set up an operator to use the BoolTool after I set a position and modifier on Selected object and a different one on the Active object. I basically need to move the selected object up ...
9
votes
1answer
19k views

Duplicating a mesh object [duplicate]

I would like to duplicate a mesh object, but on a particular object. Right now this is working: ...
3
votes
2answers
1k views

Start script on open blender file

I have written up a script for my model. But there is a bit of a problem with it. As in I have to run the script every time I open the file. I want the script to run automatically when I open the ...
3
votes
2answers
2k views

Copying an object with python without actually creating a new object

I ran across this script on another forum and would like to implement it. However, I'm running into a major bottle neck (performance-wise) when it gets to linking the new objects back to the scene ...
17
votes
3answers
15k views

How to get keyframe data from python?

I am looking for help on how to export armatures and their animations in a custom export script. I wish to have an animation format similar to BVH, i.e. a bunch of ...
18
votes
2answers
14k views

how to use BMesh to add verts, faces, and edges to existing geometry

I've puzzled about this for a while, but haven't found an answer I understood. This snippet below does add geometry (3 verts and a face) but it also generates an error, Does going to object mode make ...
10
votes
2answers
2k views

Alternate between user input and automation in one-step script

I would like my script to do the following : Save selected object's name and add an object (automation) Let user move the added object where he wants (user input, stopped with leftclick) Move the 3D ...
13
votes
3answers
3k views

2D solidify. Is it possible?

Is there a way to make some "2D solidify" from edges to faces. (It's about creating roads from GIS data). I've tried Skin modifier, converting to curves with depth and back to mesh, but all the ...
11
votes
3answers
5k views

Duplicating non primitive mesh with Python

I've created a mesh I want to duplicate using python with specifications for the new duplicate's coordinates. How do I do that?
8
votes
2answers
6k views

How to cut a mesh into smaller pieces with python?

I have a big terrain object, I'm trying to write a script that cut it in smaller pieces and then I will export the pieces to other formats. This is required by a game engine because the mesh, if not ...
8
votes
2answers
4k views

Remove Doubles on multiple objects

I'm trying to run the remove_doubles edit command on multiple selected objects. This is kinda what I got so far... ...
6
votes
2answers
7k views

What units does the rotation argument expect when creating objects?

I want to create a lamp in blender using python. I want to give the lamp some rotation. As per the documentation I can set the initial rotation using a tuple of numbers in the function call like this <...
4
votes
3answers
7k views

How to find number of animated frames in a scene via python?

I need to find the number of animated frames after importing a bvh file in blender. scene.frame_start and ...
6
votes
2answers
2k views

Limit “prop_search” to Specific Types of Objects

Currently working on a piece of custom UI that contains an object selection box. layout.prop_search(scene, "myselection", scene, "objects") I'm wondering how I ...
3
votes
1answer
2k views

Generate video sequencer project from a script

I have a number of different MP4 files. I want to create a Blender project file that has these files in a set order and each video stream starting at a set start time. I know the files, I know the ...
2
votes
2answers
1k views

Add toggle hotkey to custom checkbox

I have a self made checkbox in a script. Now I want to create a hotkey in the Input manager to toggle it. What I have done so far is to create a keymap item with ...
10
votes
3answers
1k views

Replace matrix @ vector list comprehensions with something more efficient

I'm looking to replace list comprehensions like the following with something more efficient and I was wondering if numpy can be used. ...
8
votes
3answers
2k views

How do I Create a script for geometry I create?

I was wondering, is there a possible way of selecting an object I create in blender and generating python code from it, so I am able to generate the object via code? I was wanting to do this for ...
6
votes
1answer
2k views

Check if active object has a modifier

How can I check if the Active Object has a specific modifier so that when I run my code, it doesn't add the modifier again to the object? It should add the modifier only to the object which does not ...
2
votes
1answer
67 views

Is the active object and zeroth selected object always the same?

I see a lot of scripts on BSE that use for example bpy.ops.mesh.primitive_cube_add() cube = context.selected_objects[0] instead of one of ...
1
vote
3answers
853 views

Delete all materials that aren't assigned to a face?

Ok, I have several models that because various joining and un joining, have material slots that are there, but not assigned to any faces. Im exporting and would like these gone but there are too many ...
0
votes
2answers
868 views

Is automatic “Reload from disk” confirmation in Text Editor possible?

I use an external editor for my scripting. When I return to Blender I want the script in the text editor to reload my changes. Blender does indeed detect the changes (red button) which is great but it ...
23
votes
2answers
4k views

Blender UI Multithreading Progressbar

The following question might've been asked several times, but I've found no satisfactory answer. Short question: How can I show progress of background task in Blender UI? Explanation: I have a ...
7
votes
3answers
4k views

How to remotely run a Python script in an existing Blender instance?

I don't want to use /Application.../blender -P my_script.py but I want to tell a running Blender process to execute a script. Is there an existing method to tell ...
36
votes
3answers
55k views

Selecting an object via scripting?

As shown below, I have 2 nested spheres, each with a different material (inner = "1", outer = "2"). Ultimately, I need to select the inner sphere (material "1") via ...
19
votes
4answers
34k views

How to get Python multiprocessing module working on windows?

I am trying to run a script within Blender that utilizes multiprocessing module. According to documentation it is possible to use it ( see note at the end of "...
5
votes
3answers
2k views

Problem with casting rays from the camera into the scene for each pixel

To retrieve information about the objects that lie behind each pixel, I have to cast rays into the scene for each pixel of a rendered frame. My problem is that the ray directions which I calculate ...
8
votes
4answers
11k views

How to completely remove all loaded data from Blender?

I'm implementing a Blender Python script to do batch conversions. It works like this: for each model file found in a directory: Import the model Process it Export in other format The problem is, ...
6
votes
1answer
4k views

Getting the list of points that describe a Curve without converting to mesh

I've used mathutils.geometry.interpolate_bezier() in the past to create points for a curve using the bezier handle and knot coordinates. from the docs: ...
7
votes
1answer
9k views

Blender script import model and render it

I know python well, but I'm not familiar with blender. Is it possible to use the blender API to do this? Setup: Create a scene in which the the lights and cameras are pre-arranged. Run a python ...
7
votes
1answer
2k views

Can object parameters be set from data file?

I would like to do 3D animations. M spheres appear moving around and rotating along N frames (all spheres will appear in every frame). For each sphere at every frame, these values are saved in a ...
23
votes
3answers
11k views

Is there a way to restart a modified addon?

I'm currently twiddling with an old addon and insert some print statements for debugging. Currently I'm restarting Blender each time to see the new messages. Is there a way to 'refresh' an already ...
9
votes
3answers
3k views

How to get the 3D coordinates of the visible vertices in a rendered image in Blender

I'm new to Blender and python and here is what I need: I have a 3D model in Blender and I've set camera parameters to view a specified region of the model. The following is the rendered image: I ...
8
votes
1answer
7k views

Applying modifiers in a script

I've seen a couple of good examples of creating modifiers and applying them to objects, but they don't seem to be working for me. Or at least are only working part way. My function takes a modifier ...
6
votes
2answers
2k views

unregistering a class

I have made a new object for the Add > Mesh menu and I would like to unregister it but when I try to with: if __name__ == "__main__": unregister() I get the ...
6
votes
4answers
2k views

Update all materials, but keep their color and textures

I am working with a very large scene file that was imported as .obj. This gave me basic blender internal materials with colors and textures. I then used an addon to convert all of the BI materials to ...
4
votes
3answers
5k views

How can I export my blender model as a python script

I am using Blender 2.77. When we select File > Export from the menu, the default export options Blender gives are .3ds, .fbx, .bvh, .ply, .obj, .x3d/.wrl, .stl, .svg...
10
votes
2answers
6k views

How can I get the location of an object at each keyframe?

I'm trying to track the (x,y,z) location of an animated object. For a small test, I translated the default cube ('Cube') along the x axis and baked keyframes. The animation plays fine. I adapted the ...
5
votes
1answer
3k views

Generate random ellipsoids

I have a problem to generate random ellipsoids inside a cubic space. This is the script I wrote: ...
4
votes
1answer
3k views

Strange object.ray_cast() behavior

object.ray_cast() is not behaving as I would expect in Blender 2.77. I understand that it expects object local coordinates, but this problem happens when the object ...
3
votes
1answer
1k views

How to create a button on the n-panel?

I would like to make a custom button on the N-panel. I already went through blender's templates and amended the ui button script to 2.8 but I don't understand where and how I should implement my code ...
3
votes
1answer
750 views

Appending a sub-menu under an existing sub-menu in Blender 2.8

I can add menus to Blender 2.8 with the python code below but how can I add a sub-menu using python to one of Blenders existing menus? I'm trying to add the rtMyMenu sub-menu under Blenders Add-Curve ...
2
votes
1answer
4k views

Get bone rotation in pose mode using Python

I want to get angles of joints in armature in pose mode, see the picture below. I tried to get local rotation of bones, but I can't find a way to do this. I tried: ...
4
votes
3answers
1k views

How can I exclude a collection from rendering with Python?

Can anybody help me write a script that excludes certain collections (for rendering)? In the outliner the tooltip says: Layer.Collection.exclude and ...

1
2
3 4 5
21