Hot answers tagged

4

Fully recursive and optionally case-sensitive: import bpy def sort_collection(collection, case = False): if collection.children is None: return children = sorted ( collection.children, key = lambda c: c.name if case else c.name.lower() ) for child in children: collection.children.unlink(child) collection.children.link(child) ...


4

Well, Blender has lots of submenus and options that serve no apparent purpose, so... Anyway, Blender source code is managed by the Git version-control system which maintains a history of changes as a series of "commits". In this case, the commit that added this menu is documented as follows: commit ddeb9f8e24da6076ed76be1573cc152def5751ae Author: Campbell ...


3

Once for each collection. Just as I was about to answer this yesterday, my internet ran out, fortunately there is a bit of a point of difference. To do this once for all collections, would add the root scene collections to bpy.data.collections and then sort the immediate children of each. To sort all collections in blend in one fell swoop. import bpy ...


3

I don't think the Blender Voronoi has access to quite the same parameter as the one illustrated. Typical shader-Voronoi is based on the distances between randomly placed points, one to a cell, in a regular grid of cells. I think the specific 'wobble' effect you show is based on smoothly varying the positions of those points within the cells, without moving ...


3

How about something along these lines? import bpy scn = bpy.context.scene cols = scn.collection.children sorted_cols = sorted (cols, key = lambda c: c.name.lower()) for col in sorted_cols: cols.unlink(col) cols.link(col) There may be problems with it.. I haven't covered all the bases, and you may want to do it recursively, etc..?


2

This does not seem to be possible at all just yet. There is discussions about this issue in various places, for instance here in the bug tracker. Using Python I also have not seen a way of doing this just yet. The sorting simply relates to the time at which a collection has been linked to the scene, and cannot really be changed. The underlying issue seems ...


2

In Blender 2.80 and higher, you can use as_module(). In the above example, an unsaved text editor shows this code: def myTestFunc(): print('This is my test function, running') print('This is my test module, running') Then, in the Blender Python console on the left, you can import this: myModule = bpy.data.texts[0].as_module() Note that since this ...


2

Relative vs Absolute. The "accumulative" nature is the nature of a 3D transform, ie rotate the bone from where it is by this much about an axis. Whereas you wish to set the absolute rotation. As well as using method in accepted answer, contend you could also pre-set the rotation to zero before applying any transform, for example if the rotation mode ...


2

If the rotation is directly assigned to bone.rotation_euler then the it will not accumulate, unlike when you're using bone.rotation_euler.rotate_axis(). import bpy import math import mathutils def rotate_bone(armature, bone, rotation_euler): # Remember active object and its mode old_active_object = bpy.context.view_layer.objects.active old_mode ...


2

Make the vert.co 4d From Perspective projection of transformation matrix wiki The simplest perspective projection uses the origin as the center of projection, and the plane at ${\displaystyle z=1}$ as the image plane. The functional form of this transformation is then ${\displaystyle x'=x/z}$ ; ${\displaystyle y'=y/z}$. We can express ...


2

You can use a single line python expression as a driver, like an if-else statement. 1 if (bpy.context.scene.frame_current == 1) else 0 The reason this fails, would be if python scripts have been disabled. You get this dialog after entering a python expression when python scripts are disabled. Click on "Allow Execution". If you dismissed the dialog, ...


1

When editing the value of the keyframe you have to set both handles as well. Example on how to set the value based on our famous Operator Simple template (should work for the dope sheet as well): import bpy class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" ...


1

i managed to write one. if anyone else looking for same thing, below is simple function to test and could be starting point. select facecap head mesh and rigify jaw master (in pose mode) def bindFacecapToRigify(): obj = bpy.context.selected_objects[0] sk = obj.data.shape_keys # driver details (skname:'pbone','prop','axis','dir'), skname = '...


1

I got it working. bl_info = { "name": "Apply modifier for object with shape keys", "author": "Przemysław Bągard", "blender": (2,80,0), "version": (0,1,1), "location": "Context menu", "description": "Apply modifier and remove from the stack for object with shape keys (Pushing 'Apply' button in 'Object ...


1

Some blender basics The console is a great place to figure stuff out where C = bpy.context and D = bpy.data for our convenience. >>> C.object bpy.data.objects['Cube'] >>> C.object.dimensions Vector((2.0000009536743164, 2.0000009536743164, 2.0)) >>> C.object.dimensions.y 2.0000009536743164 >>> The height of an ...


1

Look in NodeTree.animation_data Python console code. Loop thru materials that use nodes and have animation data, if so loop the drivers collection. In simple example below find the couple of simple drivers including a driver on a value node with expression "frame" (the current frame) The drivers datapath gives the node name and the index of the socket. ...


1

There is no automatic translation, you will have to create a dictionary with the translations that is registered/unregistered through bpy.app.translations.register() and bpy.app.translations.unregister(). The Manage UI Translations add-on can help you generate the tuples from which the dictionary is generated. More information can be found in the manual and ...


1

The reason why the script doesn't work as expected is that you're keeping a reference to the object's data followed by a redo. This causes the reference to be invalid. Blender's Python API provides access to the underlying functionality implemented in C (or C++), which is why some precautions are necessary to avoid undefined behavior. Basically you're ...


1

Pose bones belong to the object If ob is our armature object, ob.type == 'ARMATURE' the pose bones belong to ob.pose.bones. The edit bones are in the armature ob.data.bones. To set active pose bone(s) to use operators see Set active bone in pose mode from Python script To get a specific pose bone knowing its name name = "Bone" pb = ob.pose.bones.get(...


1

Rotating the handles of bezier curves. Running script in edit mode on default bez (blender 2.82) There are some issues at play, eg what handle type you are using. I have set the type of both to 'FREE' For example, here is a script to rotate both handles of point 0 of bezier curve by 45 degrees about the local z axis passing through the coordinate point. ...


Only top voted, non community-wiki answers of a minimum length are eligible