Hot answers tagged

4

No Sure this is a dupe, have searched and searched, For want of a better reference https://developer.blender.org/T53617 bl_info must be declared in the module. This is because bl_info is extracted without executing code. ie the bl_info dictionary is grepped out of the addon module top level file (foo.py or foo/__init__.py) as a string where the locals ...


3

More Python thing than Blender's one, but you can: import bpy def find_meshes_recursive( root, levels=10, meshes=None ): # Initialize the result once if meshes is None: meshes = [] def recurse( parent, result, level, levels ): # Does nothing if level is reached if level < levels: # Keeps meshes ...


3

So it seems like Blender is using ast.literal_eval() for finding bl_info without execute whole addon content. As the references said, using eval to evaluate arbitrary addon would be extremely dangerous. And the potential corrupt code will also make Blender vulnerable to malware. Reference literal_eval() — ast — Abstract Syntax Trees — Python 3.8.6 ...


2

You can use bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)


2

Addons are modules In blender the addons folders are added to the system path. Addons are imported as modules. The preferences displays the path, hence for "Bool Tools" its the name of the py file object_boolean_tools and for Add Mesh Extra Objects, the name of the folder containing the __init__.py file. (add_mesh_extra_objects) Standard python ...


2

Bmesh script to remove verts not linked to any faces import bpy import bmesh from bpy import context ob = context.object me = ob.data # clean all verts not connected to faces bm = bmesh.new() bm.from_mesh(me) bmesh.ops.delete( bm, geom=[v for v in bm.verts if not v.link_faces], context='VERTS', # default ) bm.to_mesh(me) Re your question ...


2

Remesh modifier. One of the answers linked to recommends using the remesh modifier, without looking into what would be the correct settings, ie this is the code to "do it" but haven't investigated the settings, and what values to set. Loop over the objects, add a modifier, get the deformed mesh, remove modifiers update mesh. import bpy import bmesh ...


2

Again with tip to tail offset. Slight addition to @ideasman42's answer to enable globally locating to tip or tail of bone based on an offset. 0 is as above at fat end of bone (head), 1 at skinny end (tail). This is to emulate somewhat the option in copy transform constraints to locate with offset along bone. The vector (pb.head - pb.tail) describes the ...


2

Recursive generator. Test Data. At its bare basics can walk a tree and yield all objects. List comprehension is used on result to keep or weed out by some condition. import bpy context = bpy.context def walk_children(ob): yield ob for child in ob.children: yield from walk_children(child) # test call print("-" * 20) print([o....


2

The bl_idname of MESH_OT_L should be lower case and one dot only, which is: mesh.l. You need to follow the naming convention that Blender API required. It is kind of meta type that Blender used to organize the components that addon gonna registered. And also you should use MESH_OT_L.bl_idname in your panel for clearance and flexible to change your bl_idname ...


1

You could add some roughness to your collision object or to your particles. Fist Subdivide it. Next give it a Displace modifier with some texture. Cloud texture seems to work just fine. Then enable physics for Collision. The order of your Modifier stack is important. Collisions has to be last and Subdivisions has to be first.


1

Set the normal The default values of cutting plane coordinate and normal are (0, 0, 0). A zero length normal is invalid and quite likely does nothing. Test script Here is a minimal working example of a script, adds a cube, runs the operator with plane coordinate at origin and its normal as the x axis. Recommend setting up a little script like below when ...


1

Scene.objects.active is no longer valid For 2.8 to get or set the active object use context.view_layer.objects.active = ob however after an operator call the object has context, so with minimal changes def execute(self, context): add_cube(context, self.name, self.scale) self.report({'INFO'}, "Added Cube") return ...


1

When using a context in an operator you should use the context provided in the execute method, or else you risk encountering invalid context error. Although this is not why you get an error in this case. Here you can simply use context.active_object since this will default to the newly created cube. Replace your execute method with : def execute(self, ...


1

Use a setter getter Instead of setting the default of the property, emulate a property with a getter setter that retrieves the custom property when set, else some default we have set. Internal "get/set" function of property? As an example have added another intproperty in same prop group as a means to adjust the default value without any re-...


1

This looks like a path error, similar to what is described in this question. Append python script for Blender 2.8


1

Solved -- my problem was actually related to Blender's hard-coded behavior in background mode, rather than to something going wrong with the render process itself. In order to get the Viewer Node to work in background mode, you need to modify some source code and recompile Blender as described in the link, because it is disabled by default for optimization ...


1

Make and move a global bound box Result of Import, origin to bounds, run script Calculate the global bounding box coordinates of each mesh object of the selection. From it garner the median x and y, then translate globally all selected objects without parent. A bounding box is the axis aligned extent of an object. import bpy from mathutils import Vector ...


1

A way to do it: Loops overs selected meshes to get each individual center in world coordinates Then calculates overall center Loops again over them to shift their vertices considering the overall center The script: import bpy from mathutils import Vector # Choose the axis you want to center on center_x = True center_y = True center_z = False # Get ...


1

I found your question looking for the same issue. I found how to do it by looking at the code of Power Sequencer add-on. After you define your shortcut you have to add a property to the keymap: kmi = km.keymap_items.new(OPERATOR.bl_idname, 'LEFT_ARROW', 'PRESS') setattr(kmi.properties, 'bool_property', True) Then read that property from the operator: class ...


1

Select the armature bone. Further to the answer by @yhoho a pose bone has a bpy.types.PoseBone.bone property pointing to its associated armature bone. Example from python console (where C = bpy.context) , bone of interest has name "Bone", armature object has context. When unsure of things the python console is a handy way to interactively see what'...


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