New answers tagged

2

mathutils.noise.hetero_terrain(...) Returns the heterogeneous terrain value from the noise basis at the specified position. Out of interest made a little script to apply each of the noise types as a shapekey on z height of a 100x100 mesh grid. Script below, result above. import bpy from mathutils.noise import hetero_terrain as ht context = bpy.context ...


1

Set the default_value of the input There are many examples of this here, probable duplicate. Here is an answer in lieu of a long comment Set an input node value by altering its default_value property import bpy name = "Foo" newmat = bpy.data.materials.new(name) newmat.use_nodes = True node_tree = newmat.node_tree nodes = node_tree.nodes bsdf = nodes.get("...


2

Without edit bones. Edit bones can be a little tricky, in script below instead have added the default single bone object, copied it to match number of verts, joined and constrained to the empties. IMO this is a little easier to use for something like this and avoids dicking around with edit mode and heads and tails. Select a mesh object in object mode. ...


1

Set active node Similarly to Set active image node with python In the python console C = bpy.context D = bpy.data >>> node = C.scene.node_tree.nodes['Composite'] >>> node.select = True >>> C.scene.node_tree.nodes.active = node >>>


2

Processing edges twice. The logic is wrong. If an edge is a boundary of two selected faces it gets subdivided twice (for each face). These are the edges to have seam set to false To get all the edges of smooth faces. First will select smooth faces. Set the material on these faces. From these faces get the edges. faces = [f for f in bm.faces if f.smooth]...


0

The answer is similar to this question. Though all this is new from 2.81. So here are some little more information (as far as I understand all this, which seems to be new thing along the current versions). To make your script work, you can change it to: import bpy from math import * def frame_handler(scene,depsgraph): print(depsgraph) ...


0

This is an update to the original script by @zeffii for Blender 2.8x: import os import bpy import sys from math import pi dataset_name = "hotel_0" item = "/media/DATA/dataset/environments/Replica-Dataset/"+dataset_name+"/mesh.ply" out_dir = "/tmp/blender_hotel0/" os.makedirs(out_dir, exist_ok=True) # https://blender.stackexchange.com/q/36897/89335 bpy....


1

Easiest way in Ubuntu Linux is to create a Desktop launcher. Simply right click on desktop, popup menu offers create launcher option. Select. When creating the launcher, you get the option to run in Terminal. Select that option. Now every time you launch Blender from the desktop, it automatically runs the terminal.


0

The script works, however you don't assign the newly created material to any object. Therefore you're seeing the old material, that was previously assigned to the active object, in the Material Properties or the Shader Editor. If you want to assign the material to the currently active material slot of the active object, you can use bpy.context.view_layer....


2

You need to set the origin of the object to its center of mass else the simulation will become wonky. Select your object. obj = bpy.data.objects['Cube'] obj.select_set(True) While the object is selected in object mode, right click > Set Origin > To center of mass. bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN') Also, Apply ...


1

You can use a message bus subscription to do that. The following script will call a function when 'use_keyframe_insert_auto' is changing from the UI. The principle is: Obtain a subscription link using path_resolve on the scene Then use this link to subscribe in order to fire a function when the value changes Here is the code (look at the console to see ...


4

Integrate the velocity curve. Please note: Am currently working on an addon that uses 3rd party addons scipy (to integrate here) and matplotlib to plot. Displacement is the integration of the velocity curve. Instead of 10ms between points (would need frame rate of 100fps for a frame each) have spread the velocity across the scene frame range. dt is how ...


1

Some code from this answer. But adapted for bmesh and the selection aspects of this question. The principle is to start from selected vertices, and: Make a dictionary of possible links to other vertices Iterate available vertices and for each follow all possible remaining paths The code with comments: import bpy import bmesh def make_vert_paths( verts ):...


3

It seems that during rendering you need to use the depsgraph so that you obtain an evaluated object. Don't know why this is not useful when just playing the animation. So add this line: sun = sun.evaluated_get(depsgraph) In the complete function: @persistent def sun_handler(scene, depsgraph): if "Sun" not in bpy.data.objects: create_sun() ...


4

Recursively walk the tree. Similarly to https://blender.stackexchange.com/a/137866/15543 and Sorting Collections Alphabetically in the Outliner import bpy def traverse_tree(t): yield t for child in t.children: yield from traverse_tree(child) coll = bpy.context.scene.collection for c in traverse_tree(coll): print(c.name)


4

I suggest start here: How to create a custom UI? To extend the Properties Area of the 3D View you can either register a custom panel to add UI elements onto or you can append elements to existing panels. 1. Panel Blender comes with a few UI templates (Text Editor > Templates > UI ...) . I'd suggest start with UI Panel Simple ui_panel_simple.py and use it ...


3

You are setting the rotation. The code in question you are setting the Euler rotation. The resulting value will always be (x, y, z) Instead recommend make a transform (rotation) matrix. Python console example. x, y, and z are 30, 45 and 60 degrees respectively. >>> x, y, z = (radians(30), radians(45), radians(60)) >>> Euler((x, y, z)) ...


0

You can do ./blender -noaudio -b --python test.py -o //out -a to get rid of those errors/warnings.


0

First of all you can bake your animation of the baked sound f-curve, so that it becomes editable. Then you can use that f-curve value to modify any other value using drivers. In my example the Y loc of the bone is driving the Y mapping of the texture, so the checker is moving up and down (on Y axis) following the music. Check also the "stepped ...


0

So I kept playing around with this and it turns out that my script was basically fine, but trying to rename the bones during the initial duplication of objects was what was causing the problems/crashes etc. So I've broken that out into a separate function - that particular bit is specific to glb export anyway so I also added a flag to run that or not. ...


1

Setter / Getter on property Something like this can be done with an update, or setter and getter on a blender property. The operator has been ditched altogether. Because the compositor is being used, the Scene type is a natural choice. For shader nodes choose Material. The getter returns how many math nodes are in the node tree. The setter adds more if ...


2

Pathlib Here is a script that writes all text files in blend with suffix .py to a designated folder. IMO there is no need to timestamp a file name, since it is given a date when written to or touched. Timestamp a containing folder name if need be. import bpy from pathlib import Path destination_folder = "/tmp/texts" df = Path(destination_folder) #...


1

Track to Quaternion To align to vertex normal. The normal orientation with respect to vertices appear to be a track to quaternion, tracking Z in direction of normal, and using -Y as up. Since the only options for up in Vector.to_track_quat(to, up) are 'X', 'Y', 'Z' track with Y up and inverting the scale in X and Y. Simple example. Run in object mode, ...


0

Found a solution: import bpy from bpy.props import IntProperty class AddManyNodesOP(bpy.types.Operator): bl_idname = ".add_many_nodes" bl_label = "Adds many Nodes" bl_description = "Adds many Nodes" def execute(self,context): tree = bpy.context.scene.node_tree for i in range(context.scene.number_Nodes_Prop): ...


5

Each collection has a children (collection) property. Easy to figure out using the python console: >>> C.scene.collection. all_objects animation_data_clear( animation_data_create( as_pointer( bl_rna ...


1

Object distance between frames and total movement length can be done. Set frame_start and frame_end variables. It calculates selected object distance. import bpy o = bpy.context.object total = 0 frame_start = 0 frame_end = 10 bpy.context.scene.frame_set(frame_start) for frame in range(frame_start+1,frame_end+1): loc1 = o.matrix_world.to_translation() ...


1

For anyone coming upon this question in 2020, I had a similar want and wanted to use Blender from a Jupyter Notebook. I made a Jupyter Kernel to do this for Blender 2.8 here. It uses asyncio so the Blender UI is not locked when using the kernel.


1

You can add File Output nodes to the compositor to get multiple files saved from any point of your compositing without the need for any Python: You can also use Python to add more nodes: import bpy bpy.context.scene.use_nodes = True tree = bpy.context.scene.node_tree for every_node in tree.nodes: tree.nodes.remove(every_node) RenderLayers_node = ...


1

So, in the end I ended up creating the bones using new() then I converted by absolute rotation to matrix and transformed the bone by that. Then after that I added the absolute position to both the head and the tail of each bone and that got me the correct result. for i, node in enumerate(jms.nodes): scene_node = edit_bones.new(name=...


2

You can loop through all objects and check if they are parented to the armature. rig = bpy.data.objects['rig'] for obj in bpy.data.objects: if obj.parent == rig: # Do stuff pass If some objects are only connected via the armature modifier, simply check that the rig is the object of the armature modifier. rig = bpy.data.objects['rig'] ...


2

Just like keyframes look at data_path and array_index data_path is the path from the owner of the driver, array index if it is an array type, eg 0, 1, 2 for x, y, z locations. Example Y Euler rotation of pose bone "shin.L", from the context object in python console. >>> for d in C.object.animation_data.drivers: ... d.data_path, d....


0

Finally, I managed to combine image parts together with looping nested arrays. Although the script itself is not the most beautiful... I mark this answer to correct now, but if somebody is doing better that works in this context, I'll change it. So here is "monster" that I've used in this case: # First I need to order rendered part names correctly ...


0

I didn't see a response but this is the code that I used: I think the original author was CodeManX def calcpivotpoint(theobject): ob = theobject me = ob.data bm = bmesh.from_edit_mesh(me) verts_sel = [v.co for v in bm.verts if v.select] pivot = sum(verts_sel, Vector()) / len(verts_sel) return ob....


0

The script below enables you to add a new material slot for your active grease pencil. import bpy ob = bpy.context.active_object # Must be a GPencil object mat = bpy.data.materials.new(name="Mymaterial") bpy.data.materials.create_gpencil_data(mat) ob.data.materials.append(mat)


0

You can do such a multi-leveled setup using scripting and automatically run script on each startup. Just in scripting panel you can create a new text block, name it with 'auto-config.py' (the extension have to be py), and in that script check whether or not proper blend files, addons, and custom presets are accessible. In order to run the script with each ...


1

The answer is simple: the gpencil.annotate() call on the last line needs to include the argument "INVOKE_DEFAULT". bpy.ops.gpencil.annotate('INVOKE_DEFAULT')


1

I edited this a while ago for 2.7x and now for 2.83-alpha currently, this one preserves the values of the shapekeys and also hides other modifiers that could mess with the joining of shapekeys. bl_info = { "name": "Apply modifier for object with shape keys", "author": "Przemysław Bągard", "blender": (2,8,0), "version": ...


0

This does it, though it uses a separate python script instead of something automated in Blender. Use it with python3 script.py [subfoldername] [framecount]. This is based on my setup, where each render pass has its own subfolder. This will search through all the files in a subfolder, determine their frame step, and generate duplicate frames based on the ...


1

bpy.ops.object.duplicate() finishes with the duplicated object as the currently selected object. Therefore, bpy.context.object is the reference to the new object. Ex (assume object selected in 3d viewport): import bpy bpy.ops.object.duplicate() dupli_obj = bpy.context.object print(dupli_obj.name) #check the console If you run this code, does ...


0

My aim was to hide the plane object while rendering. I achieved by adding plane and fish in different collections and unlinking the plane object from all other collections and then disabling that specific collection for rendering.


0

well I come up with this script: import bpy context = bpy.context scene = context.scene bpy.ops.object.select_all(action='SELECT') for ob in scene.objects[:]: bpy.ops.object.editmode_toggle() bpy.ops.mesh.select_all(action='SELECT') bpy.ops.mesh.remove_doubles() bpy.ops.object.editmode_toggle() any suggestions for improvments? Ideally I ...


-1

Thanks everyone for you time. I manage to write a usable script with your insights and suggestions. Robert: I was able to save the lists of names to variables. But I did not find a way to use those lists for joining the objects. I guess I need more study. I ended up using the collections system as temporal holders for the objects. That way blender wont ...


0

Using Operator override Here are a couple of examples. This one finds all the mesh objects in the scene, sorts them alphabetically by name, then groups them by if they start with the first. meshobs ['Cone', 'Cone.001', 'Cone.002', 'Cube', 'Cube.001', 'Cube.002', 'Cylinder', 'Cylinder.001', 'Cylinder.002'] Join ['Cone', 'Cone.001', 'Cone.002'] Join ['Cube',...


0

Finally after investigations I got something to work. Here is example blender file where is script that exports merged image. It works properly when using images that are rendered with "full final size" where is transparent section included and other with "cropped borders". Look below for a better understanding. And here is script that is also included in ...


3

It appears that the to_mesh function no longer has an "apply_modifiers" argument in Blender API 2.80. Instead, you will need to retrieve the dependencies graph ("depsgraph") and use it to get the "evaluated" object: depsgraph = bpy.context.evaluated_depsgraph_get() obj = context.object object_eval = obj.evaluated_get(depsgraph) The new, evaluated object ...


2

Test code out in the console. Even if you are going to use a script from command line always (IMO) a good idea to test it out in the python console. (D = bpy.data, C = bpy.context) When adding an object via operator, the new object added is the context.object Notice the name below is not "Area" as there are already other area lights in the scene. Using ...


0

OK. This answer doesn't necessarily use python, but it achieves the same result. Say we have 4 pictures, and want to combine it into one image in Blender. There are many ways to do it. I'll give a few examples: 1) Individual faces for individual materials You can assign the images to individual faces in Blender. I'll use the example you provided. I have ...


4

The two verts with largest angle between two linked selected edges. the angle between the first and the last edge may be different but it's always larger than between all the other selected edges Going by images in question you have a closed loop, if the two verts are ends of selected edge path, see below. Test Script orders a list of selected verts, ...


3

Add vert at cursor in edit mode The cursor is in global coordinates. Set to local by multiplying by the objects world matrix inverse. import bpy import bmesh context = bpy.context scene = context.scene ob = context.object mwi = ob.matrix_world.inverted() me = ob.data bm = bmesh.from_edit_mesh(me) bm.verts.new(mwi @ scene.cursor.location) bmesh....


1

Assigning to Existing Classes Custom properties can be added to any subclass of an ID, Bone and PoseBone Neither are bones, so leaving that aside, can see below ID is subclass of Object not FCurve, and as such is the property is not "wired up" as a property on the fcurve. >>> issubclass(bpy.types.Object, (bpy.types.ID,)) True >>> ...


Top 50 recent answers are included