New answers tagged

0

To add to this, getting whether a property is library overridable or not is also not obvious: bpy.context.object.is_property_overridable_library('["prop"]')


0

Had the same issue but found that the Sequencer (Render Properties tab, Color Management) seemed to be the cause for colorspace change when using save_render. Setting it to "Raw" fixed the issue for me. bpy.context.scene.sequencer_colorspace_settings.name = "Raw"


2

You cannot use a bmesh element as a base type Unfortunately as possible with many blender types, it is not possible to use bmesh elements as base types to extend the class in a "traditional way". >>> class Foo(bmesh.types.BMEdge): ... pass ... Traceback (most recent call last): File "<blender_console>", line 1, in <module> ...


1

The script that plays an animation is something like this: import bpy bpy.ops.screen.animation_play() In the future, if you want to use python to do something, you can make it easier by activating Python Tooltips, which you can do by going to Edit >> Preferences >> Interface >> Python Tooltips. You can see Python Tooltips in action by hovering over a ...


1

Create POLY type curve from numpy array Script below creates a POLY type curve from 4d SplinePoint.co numpy array. Script result in edit mode import bpy import numpy as np context = bpy.context # emulate numpy data x = np.arange(0, 10, 0.1) y = np.sin(x) z = np.cos(x) q = np.ones(len(x)) data = np.vstack((x, y, z, q)).T cu = bpy.data.curves.new(name="...


2

Well, I don't know how good of a solution this is, but as suggested by @batFINGER this worked for me. if parent.type == 'CURVE': if parent.data.splines[0].type == 'BEZIER': curve = Matrix.Translation(parent.data.splines[0].bezier_points[0].co) else: curve = Matrix.Translation(parent.data.splines[0].points[0].co) mat = parent....


0

Only for first level children: # hide the parent object bpy.data.objects["parent"].hide_viewport = True # get the list of children list_of_children = bpy.data.objects["parent"].children # hide the children for obj in list_of_children: obj.hide_viewport = True Now for all level children: def recursive_child (list): children_list = [] for ...


2

UILayout.prop index argument Use the index property for single array elements. layout.prop(map.inputs[1], "default_value", text="Position X", index=0) Would point out that this is used in my answer https://blender.stackexchange.com/a/139620/15543 to link posted in your question? FWIW. For pep8 formatting put a space after a comma in arguments list. It ...


0

There is now a third and even better solution for this that does not involve misusing a driver. Custom Properties can now store datablock references. This can only be done via Python, but it's just a one-liner in the console. With your object selected, put this in the console: bpy.context.object['my_script'] = bpy.data.texts['my_script.py'] This will ...


1

This can now be done without bpy.ops. bone.constraints.move(from_index, to_index) https://docs.blender.org/api/current/bpy.types.ObjectConstraints.html?highlight=constraints%20move#bpy.types.ObjectConstraints.move


2

I now found a solution to this problem myself, so I post it here in case someone comes across this question. Instead of building the BVHTree directly from the object and transforming all returned values into the global coordinate system, it is way more handy to transform the object's coordinates once into the global space as it is shown here: def ...


0

Here's what I used, the following two lines of code did the job: arm = bpy.data.objects['Armature'] arm.data.edit_bones['boneName'].parent = arm.data.edit_bones['parentBone']


2

Unless I've misunderstood the question: You could make cylinder (a ribbon) to shrinkwrap to the surface, and in its Object > Instancing panel, set its method to 'Faces' Parent an appropriately oriented arrow-object to the ribbon, and Modifiers > Shrink-Wrap the ribbon to the surface by the projection method that best picks up the normals you're looking for....


1

Add a circle a round the object you want.Add a shrink wrap modifier to the circle and set mode to project and check negative.Then add a particle system to the circle and set it's type hair and check advanced.Under emission set source to verts.Check rotation and set it to Normal.Then create an arrow mesh.Under render in the circle's particle system set ...


1

I don't know exactly how to copy/paste nodes between materials, but this solution works anyway. I suggest to have a reference to the image texture node you want to duplicate inside your blend file data. To do this, choose any material that will be used as source (srcmat in my example), and add the image texture node you want to duplicate in its node tree (...


2

AFAIK there is no native bmesh function to do this. The way I have done that in the past was to construct a new mesh manually, and propagate it to a new mesh datablock using the Mesh.from_pydata() function the Mesh datablock offers. code explanation First, get the mesh itself from edit mode. the ensure_lookup_table() calls are mandatory, otherwise you ...


0

That's no longer the case at least from blender 2.81 (could be also from lower versions) Open the Text Editor and when you want to execute press ALT+P (or in the menu Text > Run Script) Also, since now it's not the Python Console, all the errors/prints will be in the System Console (Window > Toggle System Console) And make sure you import what's needed (e.g....


1

I usually suggest making a human readable temporary variables. They will immediately show everyone who's reading the code what they mean just like comments. isShadingTypeMaterial = (area.spaces[0].shading.type == 'MATERIAL') isShadingUseSceneWorld = (area.spaces[0].shading.use_scene_world) if isShadingTypeMaterial and not isShadingUseSceneWorld: ...


2

I would also improve readability by reducing the maximum line length. shading = area.spaces[0].shading if (shading.type != 'MATERIAL' or shading.use_scene_world): intensity /= pow(2, (context.scene.view_settings.exposure))


1

Making that happen? Given of-course there is a scene, the only way I'm aware of to have set mode operator fail is to have no active object. Calling op to object mode from object mode is not an issue. Is it possible that in your code this can happen? Are you running from a timer thread? Recommend editing a script example inTO question showing giving more ...


1

You can check which mode you're in with the following line: mode = context.active_object.mode And then do things correspondingly, such as switching to object mode when you're in pose mode for example. Or you could use a try/except statement: try: bpy.ops.object.mode_set(mode='OBJECT') except: pass Hope this helps.


0

import bpy import bmesh context = bpy.context ob = context.edit_object me = ob.data bm = bmesh.new() # create an empty BMesh bm = bmesh.from_edit_mesh(me) # checking for face selected selFaces = [f for f in bm.faces if f.select] # checking for edge selected selEdges = [e for e in bm.edges if e.select] if selFaces: bpy.ops.mesh.select_linked(delimit={...


0

print(bpy.utils.resource_path('LOCAL')) #Gives the default file locaton print(bpy.utils.resource_path('USER')) #Gives the blender installation location You can use this as reference to go to other directories.


0

I achieved it in this way (it needs polish btw): import re import bpy def lookFor(txt): t = re.findall(r'"([^"]*)"', txt) return t amount = 1 boneName = 'null' boneNameLast = "null" for action in bpy.data.actions: for fcurve in action.fcurves: boneName = lookFor(fcurve.data_path) if boneName != boneNameLast: ...


0

Alright so what worked for me is this: For every cubelet the cubelet.data.vertices are all in the same grid cell so to speak. That means it's not important which one of them I take to compare against other cubelets. If it was I could still iterate them and find a min/max/average to my desire. So using cubelet.data.vertices[0].co works for selecting initial,...


1

Amended code to do somewhat what you want. Shifts keyframes 0 for first fcurve, 10 for next, 20, 30... Have made it adjust only the action on the active object. import bpy ob = bpy.context.object ob.animation_data_create() # lazy way to make animation data exist action = ob.animation_data.action if action: for i, fcurve in enumerate(action.fcurves): ...


1

Window manager properties are not animatable Doh.. should have looked harder. The issue here is the use of window manager >>> C.window_manager.keyframe_insert('test') Traceback (most recent call last): File "<blender_console>", line 1, in <module> TypeError: bpy_struct.keyframe_insert() property "test" not animatable Use another ID ...


2

You are very close Can create the list in one fell swoop using list comprehension. (instead of edge_list.append(tuple(v.co for v in e.verts)) Used a tuple for vert coords as we really don't want to add or remove or sort or.. Python console code, notice don't need to print items as their repr is echoed. >>> edge_list = [tuple(v.co for v in e....


0

Haven't done much with flask, will offer this up as a suggested workaround. Try loading the mainfile outside of @route decorated methods. Putting the load operator in any route method also caused a segfault for me (Ubuntu 18, blender 2.90, python 3.82) Suspect a threading issue. The following works as expected, # batTOOLS........... from flask import ...


1

Modifiers alter mesh at a local level The hook modifier, or most modifiers modify the mesh data, not the object transform. The location of the hooked object could be estimated from all the hook empties (average there global translations). Or use a copy location constraint. Add all the verts to one group, make that the constraint target. The rotation can ...


1

Got the faces with one line def make_mesh(verteces, faces, normals, uvs, global_matrix): mesh = bpy.data.meshes.new('name') mesh.from_pydata(verteces,[],faces) obj = bpy.data.objects.new('name', mesh) # apply transformation matrix obj.matrix_world = global_matrix bpy.context.collection.objects.link(obj) # link object to collection ```


0

I managed to figure this issue out. It made a mistake using a Mesh structure from 2.9 Blender sources instead of 2.82 which is the Blender build I am running this code on. The mesh.as_pointer() does give a valid pointer to the DNA Mesh struct right away.


0

Since there was no change in the actual mesh,updating the mesh with update_edit_mesh() was not required.Also setting object context directly to "Edit"mode as opposed to a context mode_set poll() works. Code can be found here.


0

The older answers here are invalid as of 2.80. The Python API has changed, and screen objects no longer have scene as a property. In addition, the window object owns the active view layer. Now, you can: bpy.context.window.scene = someScene bpy.context.window.view_layer = someVL API doc for window object: https://docs.blender.org/api/current/bpy.types....


1

List selected edit mode vertices. Run the script with a mesh in edit mode. Prints an index list of the selected vertices. An edit mode bmesh is bound to the edit mesh. The selection is live. import bpy import bmesh context = bpy.context ob = context.edit_object # RUN IN EDIT MODE me = ob.data bm = bmesh.from_edit_mesh(me) print([v.index for v in bm....


0

In blender 2.8x it's the same things to do : rename your script file in the text editor with .py at the end check register in the Text menu (this option is greyed out until you rename your file)


0

You can try with this solution: Create a segmentation picture with each object class rendered in different color ?. It worked for me. Moreover, if you want sharp edges you can set render properties -> film -> pixel filter -> width for cycles or render properties -> film -> filter size for eevee to 0.01.


1

Ok, found it. Replace all the stuff below the cam definition with: layout.use_property_split = True col = layout.column() row = col.row(align=True) row.prop(cam, "location") col = layout.column() row = col.row(align=True) row.prop(cam, "rotation_euler")


1

If you want the properties to be identical to the original ones, you should set Slider to False or simply not include Slider at all. A Slider is a bar that fills the field from left to right. When disabled, the field has 2 arrows on both sides instead. If you use a slider you have to include min and max values or else they will be determined by Blender and ...


1

You can either call hide.socket_toggle() operator on all nodes in selection or hide each socket one by one using NodeSocket.hide property. Following demo is based on Operator Node template: import bpy def main(operator, context): node_selected = context.selected_nodes if node_selected: bpy.ops.node.hide_socket_toggle() else: ...


0

I think the question is mathematically inaccurate. Your coordinates are defined by magnitude and direction. To add a scale factor like mm or m you need to multiply these unit vector values with constants.


0

As the context object's vertices where selected in "Edit" mode, the correct command to convert mesh to Bmesh should be from_edit_mesh(), as opposed to from_mesh() which accesses the mesh datablock( as used in the above code).


1

Matrix equivalent of global scale bounding box center. Note both of these examples use the bounding box center as pivot point. Could as suggested scale the mesh, akin to edit mode scale. If scaling the mesh use local coordinates. Note this alters the mesh coordinates, but keeps the origin and object global translation same. To scale about a non origin ...


1

Sub Panels Blender now has subpanels. Recommend making "Holding Panels" and make your other panels children. Example https://blender.stackexchange.com/a/155517/15543 On rearranging panels This is easily done by rearranging the order in which each panel is registered. Maybe a poison chalice. Remember the user can move panels around. The expected ...


1

Thanks to this answer on blenerartists I now know what my error was. In order to properly convert a metaball into a mesh you have to look at the evaluated metaball. The correct code looks like this: # Create metaball object mball = bpy.data.metaballs.new("TempMBall") mball_obj = bpy.data.objects.new("TempMBallObj", mball) context.view_layer....


1

Unfortunately I don't have 50 reputation yet to comment Christophers answer, so I need to write another answer. I also had the problem of finding the texture color at a given point on a mesh. This point was calculated using this function. Christophers approach worked fine as long as the mesh was not translated. After some trial and error, I figured out that ...


-1

Use bpy.ops.transform.translate() With the argument cursor_transform=True to apply the transformation on cursor instead of selected object You can find other arguments of this operator here https://docs.blender.org/api/current/bpy.ops.transform.html


1

If you need to print your lines on blender but not the blenders so much of outputs, you can use add your-command |grep "#". "#" is a keyword You can use you own keyword for this that you can add at the beginning of statements you want to be printed.


3

After porting to bmesh, this should work again: # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This ...


1

A changed the way you selected active object and the way bmesh.from_mesh was called. from os import system system("cls") import bpy import bmesh #Assign object as a part of the active scene scene = bpy.context.scene ob = bpy.context.object vert = ob.data.vertices #Set default mode == Edit if bpy.ops.object.mode_set.poll(): bpy.ops.object....


Top 50 recent answers are included