What's the deal with Deno? We talk with a major contributor to find out. Listen now.

New answers tagged

0

Just for completeness sake So gandalf3 provided a beautiful answer applying the difference. If however, you want to actually change the values, and only fake differing values in the user interface, you can overwrite the interface instead. The idea is to display custom properties instead of the ones usually found. The custom properties can then in turn set, ...


0

Use EnumProperty callback: Property Definitions (bpy.props) — Blender Python API Basically blender will call the function in following way: list_tuple_callback(scene, context) The return of your function should look similar with the original item List[(identifier, name, description, icon, number), ...].


0

The Orange you mention is Active state of object, as other posts described, it is separated from selected object. The Red ones is selected object. Newly created object in script will be "selected" but not active by default. If you want to set it as active object: bpy.context.view_layer.objects.active = some_obj - 2.80 API For further information: ...


0

it's nothing wrong with your code. it runs just fine when it's set up correctly. You only have to encapsulate your code within the Blender Environment. I'd assume: A new Blender instance was generated as it has been launched. As you called your script its structure was bound to the Blender instance. As you called it the 2nd time the Blender instance remained ...


3

The code works just as it is supposed to work. You just need to enable Operator Search to use it. You need to select Edit -> Preferences. Under Interface check Developer Extras checkbox. Now you can find Operator Search from Edit drop down menu. Search Add Tetrahedron Errors You can select Window -> Toggle System Console to see the errors your code ...


0

From @batFinger code, fix to make it work with all axes: import bpy from mathutils import Matrix from math import radians bone = bpy.context.selected_editable_bones[0] if bone: old_head = bone.head.copy() R = Matrix.Rotation(radians(30), 4, bone.x_axis.normalized()) bone.transform(R, roll=True) offset_vec = -(bone.head - old_head) ...


0

In Blender2.9 , Wrap-Width slider can be used to place words on separate lines.


2

It is not that bad to use the second method if you're not collaborate and distribute your project with other. In other words, personal usage is fine if you do take care of naming confliction. The problem when you reload script is a common mistake that you assume that all object you imported from that module is reloaded by the reload method (imp.reload()). ...


0

so today I was trying to solve the same problem, came up with this -ugly, but working -, workaround, if we tried to set transform_orientation_slots[0].type to a non existent value, we get this error: TypeError: bpy_struct: item.attr = val: enum "" not found in ('GLOBAL', 'LOCAL', 'NORMAL', 'GIMBAL', 'VIEW', 'CURSOR', 'Cub', 'Cube', 'Cube.001', '...


3

The header of the outliner panel can be accessed through bpy.types.OUTLINER_HT_header. It is possible to add additional buttons to the header by appending or prepending a draw function which assigns the relevant operators to the layout. The draw function could look like the following, if your operator class is called EXAMPLE_OT_something. def draw(self, ...


1

You need to split your layout or column or whatever with split() method. def draw(self, context): layout = self.layout() props = context.scene.my_props # your properties col = layout.split() col.prop(props, "x_axis") # your property name col.prop(props, "y_axis") # your property name col.prop(props, "z_axis&...


1

I'm not sure why your bytes code became split into lines. I think this is stackexchange, but if this is done by bs.readBytes(0x40) you need to concatenate all lines before you will be able to decode them into floats. Decoding can be done with built-in memoryview() method or with built-in struct module, like struct.unpack('f', bs.readBytes(0x40)). After that ...


0

Solution, that generate random values, save it and allow to edit 2 neccesary values from 3 created. So, value editing not execute in real time, changes is required apply from button (is good for my script with highpoly mesh objects) import bpy from random import randint class VIEW3D_PT_monkeygen(bpy.types.Panel): bl_space_type = 'VIEW_3D' ...


0

I ended up dynamically creating + registering a class and then reassigning it back to the same mysettings property. It works in this POC, but I have to try it in the real addon. Feel free to suggest any other solutions or make edits to this one. import bpy from bpy.props import PointerProperty from bpy.types import PropertyGroup, Panel myproperties = [ {...


0

bpy.path.abspath() Returns the absolute path relative to the current blend file using the “//” prefix. TLDR; Just call bpy.path.abspath(your_path) to get the absolute path representation. There is no reason to display the absolute path nor convert it because the user can set it to absolute or relative in the File Browser (N): Also notice: there are ...


0

Not totally sure this answer the question, but here is some code to check if an armature has bone heads visible by the camera. The alternative way to understand the question could be: which armature is not totally enclosed by a mesh. But, the principles of the script: create and use a sphere that will be placed and scaled at bone heads locations parse ...


0

you can go to the viewport display settings , and then check In front setting do that you can see the bones in the front of all the mesh


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

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


0

Maybe it'll help you **>>In the Timeline panel, display the layer property containing the keyframes you want to copy. Select one or more keyframes. Choose Edit > Copy. In the Timeline panel containing the destination layer, move the current-time indicator to the point in time where you want the keyframes to appear.**


2

Rough Surface 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. Force Field ...


0

Open a new script , using the template ui_menu Add these lines to make it able to become an addon import bpy bl_info = { "name": "MY_OWN_MENU", "blender": (2, 80, 0), "category": "Object", } class CustomMenu(bpy.types.Menu): Save the file anywhere, using notepad and change the fileextention to ....


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


0

Here are some rough replacements for the functions you posted: import bpy from bpy_extras.image_utils import load_image from bpy_extras.node_shader_utils import PrincipledBSDFWrapper # Sets a base color map to be used by the material. def set_base_color_map_filename(mat, filename): ma_wrap = PrincipledBSDFWrapper(mat, is_readonly=False) image = ...


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


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


0

If you need to run any script in any context area. You might need to use a new operator to make the shortcut available due to the lack of operator. The one that scripting editor used will poll the context and only work in scripting area. Code import bpy def create_summary(text: str, length: int = 300) -> str: return f"Code Preview:\n\n{text[:...


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


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


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


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


0

I needed this to work even if Image Editor is in different window so I used an additional loop for Bleneder windows: import bpy img = bpy.data.images.load('My Image.png') for window in bpy.data.window_managers['WinMan'].windows: for area in window.screen.areas: if area.type == 'IMAGE_EDITOR': area.spaces.active.image = img


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


0

I found the answer : bpy.context.object.data.edit_bones[0].select = True before bpy.ops.armature.subdivide() enables the subdivision


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 method works for me: Export as .fbx, unselect "empty" from object types Import .fbx in to a new Blender project et, voila


2

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


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


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

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


0

to select vertices with standard API, you need to deselect everything and leave editmode. Setting .select to False doesn’t work, only setting to True is supported using this approach. import bpy bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT') for v in bpy.context.object.data.vertices: if v.co[1] > 0: v....


0

Just to follow up with the help from @batFINGER: import bpy o = bpy.context.selected_objects[0] for fc in o.animation_data.action.fcurves: fc.extrapolation = 'LINEAR'


0

you need specify the "bone" method myPoseBone = bpy.data.objects['metarig'].pose.bones["thigh.R"].bone myPoseBone.select = True


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


1

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


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


0

I found a hacky way around my issue using ctypes. It's not perfect, but it's something. The magic line ended up being ctypes.windll.user32.mouse_event(self.MOUSE_RIGHTUP) With the full code now reading: import bpy, ctypes class UnrealRightClick(bpy.types.Operator): """Timer that decides whether to display a menu after Right Click"&...


0

Well, I that's not the case. It's selecting the same material, not the color in a material. What I'm saying is that assign a material to the object, and add a image node to the diffuse color of that material. and u paint on that image texture. Then, u wanna select certain color face. If do the SHIFT-G--->MATERIAL, it's actually gonna select the whole face ...


Top 50 recent answers are included