New answers tagged

2

bpy.ops.wm.context_set_enum(...) Setting a value from a context path for a shortcut use one of the bpy.ops.wm.context_set... operators >>> bpy.ops.wm.context_set_ boolean( enum( float( id( int( ...


2

For operators use context. Given the self in the question code, making the assumption you are writing an operator Further to the answer of @RoufirHassan by way of explanation, looping over the collection objects de-selecting and selecting single, was not changing the active object. Adding context.object to print statement would confirm this. Is the active ...


3

You're better off using bpy.data.objects to manipulate them. This way you don't need to rely on what is selected, all you need is the objects name. import bpy mod_name = 'My-Mirror-Modifier' for obj in bpy.data.collections["My-Collection"].all_objects: if obj.type == 'MESH': mod = obj.modifiers.new(mod_name, 'MIRROR') mod....


1

Select all the meshes in your collection and add a mirror modifier. But as you said it will only mirror the active object ( active object = last object selected with different colored outline). So in order to mirror every single object just type (Ctrl+L) > modifiers. It will link all objects with the same modifier. You can use it for any other modifiers.


0

You add this to the unregister function, pointing the the UI script of the affected editor: bpy.ops.script.python_file_run(filepath= bpy.utils.resource_path(type="LOCAL")+"\\scripts\\startup\\bl_ui\\space_sequencer.py") bpy.ops.script.reload()


2

Put them in a collection IMO the simplest way to do this is, as suggested scene_lights = [ob for ob in scene.objects if ob.type == 'LIGHT'] One light object could have the same light data as any or all of the lights in a scene. Even if there are few lights, checking that the data belongs to an object in the scene could prove less efficient than above. If ...


0

use the script below: import bpy light_set = set(bpy.data.lights.keys()) obj_set = set(bpy.data.objects.keys()) # light data doesn't update by deleting: light_set.intersection_update(obj_set) light_objects = [bpy.data.objects[name] for name in light_set]


0

You can also do it without operators import bpy for ob in bpy.data.objects: # Skip things without materials (armatures, etc.) if not hasattr(ob.data, 'materials'): continue while len(ob.data.materials) > 1: ob.data.materials.pop()


1

You can test whether menu_func is already part of _draw_funcs list and if so, do not prepend: def register(): bpy.utils.register_class(CUSTOM_OT_operator) if hasattr(bpy.types.VIEW3D_MT_uv_map.draw, '_draw_funcs'): if menu_func.__name__ not in (f.__name__ for f in bpy.types.VIEW3D_MT_uv_map.draw._draw_funcs): bpy.types....


0

You can some how "try" to unregister it before register in main function. And also keep track of the last registered object, a quick way is set an attribute in bpy: if __name__ == "__main__": if not getattr(bpy,'temp_addons', None): setattr(bpy,'temp_addons',[]) try: add_list = getattr(bpy,'temp_addons', []) ...


3

For Blender >2.80 this will work. Select all your objects and run this in the scripting panel. import bpy for object in bpy.context.selected_objects: obj_loc = object.location new_empty = bpy.data.objects.new( "empty", None ) new_empty.location = obj_loc object.parent = new_empty # swap this line around to parent the other way ...


4

The simplest way is to use bpy functions. you should set image's filepath and just save like below: import bpy # create new image or just find your image in bpy.data image_new = bpy.data.images.new(name = 'newimage',width=1024,height=1024,alpha=True) image_old = bpy.data.images[0] # saving image_new which is created above mypath = 'D:/01 Projects/mytexture....


2

I think you can use Python's exec() or eval() to do this, if the operator is already registered import bpy rig_id = "i8fj1rbnfbd76bf5" op = eval("bpy.ops.pose.rigify_limb_ik2fk_" + rig_id) # or with exec # exec("op = bpy.ops.pose.rigify_limb_ik2fk_" + rig_id) # now you can call op op(prop_bone='upper_arm_parent.L') # and rest ...


1

Using bpy.ops is really not recommended, as it needs context. The context will be wrong. I suggest this instead: If you want to create only 1 data block of a material: import bpy scene = bpy.context.scene mat = bpy.data.materials.new("My Material") mat.use_nodes = True nodes = mat.node_tree.nodes node_attribute = nodes.new(type="...


-2

You can try something along the lines if for obj in bpy.context.selected_objects: bpy.ops.material.new() ... Although bpy.ops are operators intended for use through the UI, not direct indicated use in scripting.


0

Look at this link. the difference between matrices is described here: How can I manually calculate bpy.types.PoseBone.matrix using Blender's Python API?


0

you need relative transformation matrix which I have explained here: How can I manually calculate bpy.types.PoseBone.matrix using Blender's Python API?


2

Set matrix_parent_inverse See Does a child object inherit the matrix from the parent? Key here is that the origin of local space is calculated from the basis matrix (what you see in the transform UI) and its parent inverse matrix. There are a number of ways to achieve desired result: set the empties matrix world to that of the original and set both the ...


0

Not sure if this answers your question, but you can Shift-Click vertices in Edit Mode to select multiple of them. If you select 2, and then press "F", an Edge will be formed between them. If you select 3 or more and press "F", a Face will be formed between them.


1

Especially if it's targeted to a specific community, your best shot (IMO) would be to advertise what you are doing as widely as possible. Post about your addon in forums, on your homepage/blog (if you have...), maybe also Blender Market etc. as early and transparently as possible. Then, whenever you encounter one of the scammers trying to make money of your ...


0

Problem solved with global variable and function which registered as blender timer. status = {'prev': None, 'new': None} def set_status(text): try: status.update({'prev': status['new'], 'new': text}) except: pass def status_timer(): try: if status['new'] != status['prev']: bpy.context....


2

I have found a solution to this. #Retrieve the current roation current_q = Quaternion((kf_w.co[1], kf_x.co[1], kf_y.co[1], kf_z.co[1])) current_eulr = current_q.to_euler() #Element-wise multiplication with a weight vector new_euler = Euler((x * y for x, y in zip( weights,current_eulr )), 'XYZ') new_q = new_euler.to_quaternion()


2

You can set the index of the list to 1, iterate through the upcoming slots, call and override the context of material_slot_remove(). Demo on how to remove all slots > 0: for obj in bpy.context.selected_editable_objects: obj.active_material_index = 1 for i in range(1, len(obj.material_slots)): bpy.ops.object.material_slot_remove({'object': ...


0

When I remove a material in the ui, this is echo'd: bpy.context.object.active_material_index = 2 bpy.ops.object.material_slot_remove() Looks like the documentation live here. Hope that helps, Koen


0

Replace constraint_orientation with orient_type. Links aren't ideal because they might die. If there is a way to add this more permanently, please let me know. https://blenderartists.org/t/2-80-cheat-sheet-for-updating-add-ons/1148974


4

Not sure what do you mean the second one but you can select the second one with further conditional list: [area for area in bpy.context.screen.areas if area.type == 'IMAGE_EDITOR'][1] And also there are properties x and y for area type, which indicate the bottom-left corner position in your screen. You can write some sorting function to select the desired ...


3

The script here is correct but you have few high value so this is not really visible, or they are in hidden parts. I've added a magnify factor to compensate if wanted: Updated file:


2

From the first script, just manage the selections in order to use the bpy.ops on each one separately: Deselect all once you get the selected ones. Select before using bpy.ops and deselect after that. sel_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH'] for obj in sel_objs: # <<<<<<<<<< obj....


0

Here the updated code after following batFINGER suggestions import bpy import os from mathutils import Matrix,Euler WORKING_DIR = "G:\Progetto QA\RR PSD Gephryn\Export\Obj" file_name = "RRGEF1_An_LV-pi_1226.obj" file_loc = os.path.join(WORKING_DIR, file_name) #import object imported_object = bpy.ops.import_scene.obj(filepath=file_loc,...


4

If you know the objects by name (names are unique), you can get them by global data access: curve = bpy.data.objects["BezierCurve"] hook = bpy.data.objects["Empty"] Or even better per scene in context if you'd like to turn this into an operator later on: curve = bpy.context.scene.objects.get("BezierCurve") hook = bpy.context....


1

You can use BlendDataImages.load() to load and assign the image to the texture node in one go. Following example code is based on Control Cycles material nodes and material properties. import bpy # Get the material mat = bpy.context.object.active_material # Get the nodes nodes = mat.node_tree.nodes # Clear all nodes to start clean nodes.clear() # Create ...


2

You are trying to access a member named query of your operator on lines 53 et 63, but it doesn't exist. Instead you want to access the property group you created in your register method : context.scene.QueryProps_query.query. Side note : Don't use bpy.context in an operator, because it is not always the right context. (L.28) Use the provided context ...


1

Just set layout.use_property_split property in your draw method to True: def draw(self, context): layout = self.layout layout.use_property_split = True layout.use_property_decorate = False # No animation. ... Custom Panel Example based on the add-on template from: How to create a custom UI? bl_info = { "name": "Add-on ...


2

There is a G-code importer addon for Blender 2.8 here. https://github.com/Heinz-Loepmeier/Blender-Gcode-Import The beveling/meshing of the curve is best done with Blenders internal curve editing tools. You can choose a custom bevel profile there, that will get rid of unconnected geometry around the corners.


2

Find Image Editor views from screen.areas with filtering and call view_zoom_ratio operator with Overriding Context. import bpy override = bpy.context.copy() for area in bpy.context.screen.areas: #if area.type != 'IMAGE_EDITOR' or area.ui_type != 'VIEW': # Image Editor View only #if area.type != 'IMAGE_EDITOR' or area.ui_type != 'UV': # UV Editor ...


1

from sys import path path.append(bpy.path.abspath("//")+'/../Scripts') from fbx_collection_export import export


0

So why can't I use bool on a simple bend cylinder? It is even meshed! In your screenshot it's not a mesh. You can't use the boolean modifier with a curve object, even if it's beveled. You have to first convert it to a mesh. I am not a Python developer, so I don't know how to perform that step in code, but that is likely what your problem is. Edit: Here is ...


0

############################################################# # imports : import bpy from mathutils import Vector ############################################################# # Add a Cube and Get the initial local coordinates of vertex id 0, # Get the initial Cube matrix_world, # Calculate the initial vertex id 0 Global Coordinates : bpy.ops.mesh....


1

You can't doing logic operation when defining class attribute in python. To customize the layout of redo panel—the dialog box that usually came out when you call operator—is using draw method. Say you want to certain property is hidden when you change another property, first you define property to toggle the change, with EnumProperty options: EnumProperty( ...


1

Just set the keymap item identifier to WindowManager.call_menu and assign bl_idname of the menu to the name property. Basic example on how create a shortcut to call a menu using CtrlW: import bpy class SimpleCustomMenu(bpy.types.Menu): bl_label = "Simple Custom Menu" bl_idname = "OBJECT_MT_simple_custom_menu" def draw(self, ...


1

You can usually retrieve the active object with: bpy.context.active_object or bpy.context.object If you need to take the view layer into account: bpy.context.view_layer.objects.active Chances are your view layer is already set, but if the view layer needs to be set, you can first do: bpy.context.window.view_layer = view_layer [source] To make sure the active ...


0

This is kind of a hack: shoutout to dagtholander for his car model onsketchfab And the node setup is really easy: Works only with shade smooth! change spherical to quadratic sphere for more difference


Top 50 recent answers are included