New answers tagged

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

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" ...


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 ...


0

That code worked in 2.79? Please when posting code in future make sure you leave in all relevant lines. eg in question what is o, i, u, v Very little difference between this answer and the following, real toss up between answering and closing as duplicate, which I'll leave for others. Quicker to answer and hence confirm in 2.82. Get/Set coordinates for UV ...


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

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

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 ...


0

Code works as intended. Just had to restart blender for change to my script to take effect.


0

Add and link the vertex colour node. Adds a new material using mat = bpy.data.materials.new() Recommend: almost never use bpy.ops.materials.new() The material bpy.data.materials[mat] in script in question is confusing and varies dependant on pre existing materials "Material" and "MyMaterial". Notice I used the index of the io when making links. Could ...


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 ...


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 ...


0

Use bpy.context.object instead of bpy.context.scene.objects.active that does not work in 2.8x. Works fine in 2.81:


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 ...


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 ...


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 ...


0

Python Tooltips needs to be enabled in Edit > Preferences > Interface.


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 ...


0

Ok, so i found the answer: Since bpy.ops.object.convert() needs a context the only way i managed it to work is: obj.select_set(True) bpy.context.view_layer.objects.active = obj bpy.ops.object.convert(target='CURVE') Though, it's quite weird that i have to 'manually' select an object to be able to use it, why not just obj.convert()? I'm not sure if method ...


0

You simply go to Edit/Preferences.../Interface and tap the Developer Extras checkmark.


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) ...


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 ...


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 ...


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. ...


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 ...


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

Mesh transform # transform the mesh using the matrix world ob.data.transform(ob.matrix_world) # then reset matrix to identity ob.matrix_world = Matrix() Recent answer where I used Mesh.transform Problem with rotating objects by script


1

Although @batFINGER has provided a more complete answer, I was part way through this and thought I'd share an alternate way using a context override: # toggle xray for 3d view in all windows import bpy for window in bpy.context.window_manager.windows: screen = window.screen for area in screen.areas: if area.type == 'VIEW_3D': ...


1

Often the UI code gives clues Turn on developer extras in user preferences and can right click and view source of most UI elements. Do this over toggle xray button and It takes us to the draw code, in text editor, of the operator button in 3d view. In space_view3d.py row.operator( "view3d.toggle_xray", text="", icon='XRAY', ...


2

Change driver type to scripted expression, (from sum variables) call your variables say sk1 and sk2 and make the expression 3 * sk1 + 2 * sk2 or sum(3 * sk1, 2 * sk2) Currently you are typing an expression var * 3 into the name field of the variable hence the error. To do this with sum variables driver type would need to add the sk1 variable 3 times ...


0

Window Manager keeps track of registered operators Lets say we add a property to the simple operator template, and make it register - undo class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" bl_options = {'REGISTER', 'UNDO'} xxx : bpy.props.StringProperty(...


0

The manual page you've linked is for Blender 2.81 and is up-to-date. If you're using an older version of Blender you'll have to consult the matching version of the manual. The documentation of bpy.types.Object in Blender 2.79 can be found here.


3

Window Manager keeps track of registered operators Lets say we add a property to the simple operator template, and make it register - undo class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" bl_options = {'REGISTER', 'UNDO'} xxx : bpy.props.StringProperty(...


3

You can just add a property to your operator class. This is done by inserting a line between the class declaration and the class methods. Both bl_idname and bl_label are properties, these are inherited from bpy.types.Operator. So lets say you want to add a property to an operator that prints monkey names. The property will be called my_monkey: class ...


0

Ok got it finally. You need set active Image Texture node: mat = bpy.data.materials['<Your material name>'] mat.node_tree.nodes.active = mat.node_tree.nodes.new('TEX_IMAGE')


0

The current workspace can be changed to the UV Editing workspace through: bpy.context.window.workspace = bpy.data.workspaces['UV Editing'] This assumes that a workspace named UV Editing exists. In order to check for the case where it doesn't exist, use bpy.data.workspaces.get('UV Editing') instead and verify that the returned value is not None. The ...


3

It's indeed tricky getting all the details sorted but it is possible to make it work properly: (Minimal) Example: https://gist.github.com/p2or/4635887cfe6ed9e652eadc8aa7585a87 Data Structure I'd suggest create a nested collection for your objects as part of the main collection (users), register e.g. per scene to get your data structure working and then ...


0

import bge cont = bge.logic.getCurrentController() cont.actuators["Motion"].dLoc = (0, 0.1, 0) cont.activate(cont.actuators["Motion"]) There are 3 important things you are missing. A link to the python API which tells you what all the field names are https://docs.blender.org/api/2.79/bge.types.KX_ObjectActuator.html?highlight=actuator#bge.types....


0

I'm presuming that reload_xref is meant to be reload_lib. In your Reloadlib class you can create a StringProperty to pass the name of the library into: class Reloadlib(bpy.types.Operator): """Reloads the current Library""" bl_idname = "my.reload_lib" bl_label = "Reload" #2.8 library_name : bpy.props.StringProperty() #2.79 #...


1

The type enum property items for the operator is populated based on selection. The type enum is an example of a dynamic enum that is populated dependant on selection. As mentioned in my answer to this related question Add shortcut for Merge Last, and Merge First if you use col.operator_enum("mesh.merge", "type") you get the available options. import ...


0

Make sure you are using the right version of Blender that has those options. You can see the options in the error below. bpy.ops.mesh.merge(type='PRINT_ERROR') TypeError: Converting py args to operator properties: enum "PRINT_ERROR" not found in ('FIRST', 'LAST', 'CENTER', 'CURSOR', 'COLLAPSE') Your error shows only 'CENTER', 'CURSOR' and 'COLLAPSE' ...


1

If you read the python console start message you will notice that some modules and some variables are builtin or have been imported for our convenience. eg bpy and C = bpy.context. PYTHON INTERACTIVE CONSOLE 3.7.3 (default, Apr 3 2019, 19:16:38) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] Command History: Up/Down Arrow Cursor: ...


0

I have similar situation recently, got thousands of objects and only needing to clear certain channels. I was trying to see if I could find Python script, but apparently Dope Sheet have Summary feature and you can quickly filter out Channels of your selected Object(s) by "Name". So this is super handy as you can search for Scale, and then select all and ...


0

For Blender 2.80/2.81 you can try this: import bpy import bmesh mesh = bpy.data.meshes.new("myBeautifulMesh") # add the new mesh ob = bpy.data.objects.new(mesh.name,mesh) col = bpy.data.collections.get("Collection") col.objects.link(ob) bpy.context.view_layer.objects.active = ob verts = [(1.0, 1.0, 1.1), (0.0, 0.0, 0.0)] # 2 verts made with XYZ coords ...


1

Drive the default_value property of a particular input channel. >>> n = C.scene.world.node_tree.nodes.new("ShaderNodeMath") >>> d = n.inputs[0].driver_add("default_value") >>> d.driver.expression '0.5' >>>


0

A working example based on answers given. Given the struggles of How to draw Object selection with eyedropper layout using Python script here is an edit to the script from that question Puts a panel in the "scene" tab of the properties area. import bpy from bpy.props import PointerProperty class TEST_PT_layout_panel(bpy.types.Panel): bl_label = "...


0

Find the object first (by name if you wish), then access the armature. The armature is the data of the object. It has an edit_bones property, but this property is only available in edit mode. This means we have to switch to edit mode first. import bpy ob = bpy.data.objects['Armature'] armature = ob.data bpy.ops.object.mode_set(mode='EDIT') # get specific ...


-1

Finally I got the Answer and this Link Controling compositor by python has some Errors in the solution so i have finally solved this question with the help of that reference and thanks for Commenting the link Error is # link nodes links = tree.links link = links.new(image_node.outputs[0], comp_node.inputs[0]) error in the second line link = links.new(...


2

Override the context. Test run, collapses "Collection 1" To hide one level the operator used is bpy.ops.outliner.show_one_level(open=False) enable developer tools in prefs to display [find link] If we invoke an operator in outliner from mouse or button then the context.area is an outliner, if we run it from the text editor, for example, it's a text ...


Top 50 recent answers are included