# Tag Info

## New answers tagged python

0

You should calculate the midpoint manually, then the difference vector that moves vertices and finally move selected parts in local coordinates because blender stores vertex-locations in local coordinates. this code does such work: (just enter your desired value into world_pos variable) import bpy from mathutils import Vector as vec, Matrix as mat # this is ...

0

So, it appears that you cannot explicitly tell a collection to turn off (exclude or turn off the check box) via Blender's python api. Evidently .exclude is not available to be set. The way I finally managed to do this is by turning off the viewport display of the collection, which in turn turns off the viewport display and render flags of all the objects in ...

0

The problem was being caused by residual settings from other software installations I no longer have installed, which made use of Python38, the same one being referenced in the error message in Blender. Step-by-Step: Go to Control Panel Use the search bar to search for "environment", then click on "edit environment variable for you account&...

2

check this out: The modifiers are just sorted in an array where the first is on position 0, the second on position 1 and so on. import bpy for o in bpy.context.scene.objects: if o.type == 'MESH': if o.modifiers: if o.modifiers[0].type == "SOLIDIFY": print("solidify modifier is on top for", o.name)...

1

Consult the docs. AFAICT you are under the wrong impression of what user clear does. user_clear() Clear the user count of a data-block so its not saved, on reload the data will be removed This function is for advanced use only, misuse can crash blender since the user count is used to prevent data being removed when it is used. reload, being when the blend ...

2

Batch remove. In latter versions there is the ability to batch remove a number of ID objects in one fell swoop. >>> D.batch_remove( batch_remove(ids=(id1, id2, ...) .. method:: batch_remove(ids=(id1, id2, ...)) Remove (delete) several IDs at once. WARNING: Considered experimental feature currently. Note that this function is quicker than individual ...

5

Set the text argument. As with all properties in blender, can set the text argument to display something other than the property name, (the default) def draw(self, context): scene = context.scene col = self.layout.column(align=True) col.prop(scene.display, "light_direction", text="") Also note the usage of context as passed ...

5

Select Mesh Objects with ngon faces. XY Problem. The issue with the exporter is ngons ie meshes with faces using more than four vertices. Rather than search for anything by name, instead will search by trait. Here is an example script to select all mesh type objects with 1 or more ngon faces in their data. import bpy context = bpy.context scene = context....

0

I had the same path in User Prefs > File Paths > Scripts Removing the path fixed the problem

5

before the actual code: you can use the following code(addon) and just run the poly_grid operator by running this line: bpy.ops.object.poly_grid() and you finish the showing up by pressing ESC key. you can also manipulate the grid parameters: x_grid_size, y_grid_size, x_grid_count, y_grid_count, grid_color and this is the result: and this is the code: from ...

4

Halve the coordinates. Prob not an answer to question as asked, more so another approach without operators, mode switching or cursors.to produce the result. Since the circle has origin at (0, 0, 0) then each verts coordinate is also the radial vector. Simply halve vertex coordinate over the desired index range. Test script. import bpy bpy.ops.mesh....

0

This is not a direct anser just typical knowledge from vector maths in game engines usually you have to subtract origin from position so you localize the position vector then perform any transforms on the vectors and then re-add the origin so, x = position - origin x += scalar x += origin in your case the line bpy.ops.transform.resize(value=(0.5, 0.5, 0.5),...

8

This can be done using --python-expr. blender \ --factory-startup \ --python-expr \ "[__import__('bpy').ops.preferences.addon_enable(module=m.__name__) for m in __import__('addon_utils').modules()]" Some add-ons can be ignored, in this example {'cycles', 'render_freestyle_svg'}. blender \ --factory-startup \ --python-expr \ ...

0

Try this(change "GeometryNodes") bpy.data.objects["Cube"].modifiers["GeometryNodes"].node_group = bpy.data.node_groups["NodeTree.001"]

0

With respect to your comment: "apparently you can reuse the mesh in some way if the copies are identical, to save some computing power", perhaps you're referring to the usage of alt + D as to the usual shift + D when duplicating meshes. Using alt + D means that the duplicated mesh inherits its data from the original which can reduce memory ...

0

Thanks batFINGER for help. import bpy, bmesh, mathutils bmd = bmesh.from_edit_mesh(bpy.context.edit_object.data) nrm = bmd.select_history.active.normal #Pick normal for active element. obm = bpy.context.object.matrix_world #Get object world matrix. nrm_fixed = (obm.inverted_safe().transposed().to_3x3() @ nrm).normalized()

0

Now with the updation of Blender 3.0 (see https://developer.blender.org/rB1b44b47f69bc55af0531516fa4b2f0b5d1e0e472), we can get access to the depth buffer with the PyGPU API. Here is an example which I adapted from @reg.cs's code. import bpy import gpu import numpy as np # Parameters used to visualize depth. linearize_depth_buffer = True scale_factor = 10 #...

1

Due to BGL deprecation (https://developer.blender.org/T80730), It's safer to use the new pyGPU API whenever possible. I slightly adapted the code provided by @reg.cs and tested it on blender 3.0. It seems that there is no obvious color space issue, if the image format is set to FLOAT. import bpy import gpu # Draw function which copies data from the 3D View ...

0

This code example and related image demonstrate creation of new vertex attributes and using them in the shader network. I was not able to create string based attribute Its important to use cycles to easily see the results when using vertex attribute values higher than 1.0 import bpy from bpy import data as data, context as context from mathutils import ...

0

Hi I know this is too late, but I've found a way to set active the f-curve import bpy data = bpy.data context = bpy.context obj = context.object previous_area_type = context.area.type context.area.type = 'GRAPH_EDITOR' print(context.editable_fcurves[0].select) context.editable_fcurves[0].select = True context.area.type = previous_area_type

0

If you know the linear distance to the object and the angle the camera makes with the direction of the object (which is the plane's direction) it's easy to calculate. The vertical distance of the camera to the plane can be calculated by noting that the vertical distance divided by the distance to the object equals the sine of the angle. Obviously, this ratio ...

2

Using foreach_get and foreach_set The keyframe_insert and keyframe_delete are methods on blender object properties that can be animated, . for example the location property of the "Cube". On the default file with no animations, adding a keyframe to cube using cube.keyframe_insert("location", 0, 1) creates an action, creates an fcurve, ...

9

Local -Z axis of the camera. To get the global vector representing the camera view, it's -Z axis can multiply cam.matrix_world @ Vector((0, 0, -1)) The rotation part of a transform matrix matrix.to_3x3() will always be orthogonal or orthonormal in blender. In linear algebra, an orthogonal matrix, or orthonormal matrix, is a real square matrix whose columns ...

1

An object can be part of an arbitrary number of collections. Adding an object to a collection does not remove it from any other collection it may be a part of. When you use an operator to instantiate an object, is is automatically added to the active collection. In your case, to the Scene collection. To remove it from the scene collection, use : bpy.context....

2

Get the object data (font curve), ask for the frame and check whether it's in a specific range using python's range(). Code based on Updating text object in Blender 2.81 using python import bpy scene = bpy.context.scene obj = scene.objects['Font Object'] font_curve = obj.data def recalculate_text(scene): if scene.frame_current in range(40, 60): ...

2

Research over this subject : I have this but it seems that working in modal do not update the gui correctly between the tasks and it might freeze the interface anyway so this should work in theory, but in practice it seems that there's few flaws because on how blender handle the freezing process. (that perhaps could be resolved by using bpy.app.timers ?) ...

1

Began writing things in comment but I figured it would be too long to make sense. You don't have to use operators to do such task. The logic goes : For each object in collection For each modifier in each object IF modifier is Solidify Toggle viewport and render visibility. In python code, using list comprehension : for attr in ("show_viewport", &...

0

After some trial & error, I came up with this solutio: def get_driver_of_shape_key(shape_key): key = shape_key.id_data p = re.compile(r'key_blocks$"(.+)"$') fcurves = key.animation_data.drivers for f in fcurves: m = p.search(f.data_path) if m and m[1] == shape_key.name: return f.driver return ...

1

The point_cache still exists for the dedicated particle modifiers that are created when Mantaflow is used. There will be a modifier "Liquid Particle System" by default and additional ones are created when spray, foam or bubbles are enabled. In order to copy the relevant files for the Mantaflow simulation it advisable to simply copy the entire ...

4

As of 2021, there is an operator for this. Clear command history only: bpy.ops.console.clear(scrollback=False, history=True) Clear command history and scrollback history: bpy.ops.console.clear(history=True) Clear scrollback history only: bpy.ops.console.clear() Reference: Blender's source code here.

-1

My "solution" to this was to avoid running the script, and instead treat the object as a particle and make my modifications there. https://blender.stackexchange.com/a/231301/125759

0

check this out: import bpy for eachCol in bpy.data.collections: print("Collection:", eachCol.name) for eachObject in eachCol.objects: print(" ", eachObject.name) Test result: or if you only want the info about the selected objects: import bpy selected = bpy.context.selected_objects for eachSel in ...

3

Read the files write to text, save blend. Here is an example script. Globs all text files in folder (hardcoded, could pass as argument) Create a textblock with same stem name Read the contents into textblock Save blend to keep changes. Script, edit directory path to suit. import bpy from pathlib import Path # glob all txt files from dir_path = "/...

0

I totally missed it but there's apparently a ParticleInfo node which I was able to use. Unfortunately at present I haven't figured out how to get the shape of the particle to change (since it's based on a modifier on the object, not part of the material) but this is acceptable for my current usage.

0

Upgrade to Blender 2.90 and above bpy.ops.mesh.primitive_cube_add(size=2, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), scale=(0, 0, 0)) import bpy class HelloWorld(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "WIRES & PIPES&...

2

Here is a weird way of doing it, Since your first and second loop are independent(i guess). we can put them in separate node trees. Then control execution of these two node trees using another. Note that Auto Execution must be turned off for first two trees.

3

Make a mesh.- Your example has 4 vertices and two faces making a rectangle of two triangles, going to need a bit more geometry than that to have rounded corners. The same method applies here to making a mesh. Given blender has a built in tool to make meshes, let's make a plane with bmesh, bevel the corners, triangulate it, and scale to suit. Bevel & ...

0

Make a joined bmesh. At the risk of not re-inventing the wheel, since blender ships with an OBJ exporter As shown in [find link re joining bmeshes] can read multiple meshes into one bmesh. Start with a dummy vert to move indexing up 1 Update normals after reading mesh to update indices. Possibly other ways to do this. Increment the edge count. Test ...

0

The modifiers are evaluated by the Depsgraph. AFAIK, the Python API only provides access to the Depsgraph of visible objects. After the load, the objects must be added to the bpy.context.scene, in a way that makes them visible. Then, their modifiers are properly evaluated when accessed in Python. I've been testing with the following script. import bpy # ...

7

The Blender function that makes a poly from a point cloud is BM_vert_sort_radial_plane. /** * Makes an NGon from an un-ordered set of verts * * assumes... * - that verts are only once in the list. * - that the verts have roughly planer bounds * - that the verts are roughly circular * there can be concave areas but overlapping folds from the center ...

0

The TEXTEDIT_UPDATE option is what you are looking for. See this answer for more information.

0

you can achieve this by this script: import bpy def update_driver(): bpy.data.objects['Text'].data.body = "z = %f" %bpy.data.objects['Cube'].location.z return 1 bpy.app.driver_namespace["update_driver"] = update_driver So your text-object should be "Text" or adapt the name in the script. Your Object should ...

3

bpy.ops.mesh.separate(type='MATERIAL') Separate selected geometry into a new mesh You can use mesh.separate() in Edit Mode and pass 'MATERIAL' to its type argument: import bpy C = bpy.context # If object type is mesh and mode is set to object if C.object.type == 'MESH' and C.mode == 'OBJECT': # Edit Mode bpy.ops.object.mode_set(mode='EDIT') # ...

2

An alternative using not convex (concave) edges. Some methods to consider Similarly to How to select concave quads , bmesh edges have an is_convex property. Of the opinion for a vert to be a local minima, at least one (probably two) of its linked edges will be convex. Running for e in bm.edges: e.select_set(not e.is_convex) on test file Normal of ...

1

You have to use a version of Blender that used Python 3.7 as its Python. This will also mean checking out a version of the SVN dependency repo for that version of blender (although I think checking out the tag from the git repo and running make update will do this for you). From the other answer you mentioned: "The Python version requirements are the ...

3

Sure, you can access all settings of WalkNavigation via Preferences. Recommend use the python console to figure out: >>> C.preferences <bpy_struct, Preferences at 0x1108d8a28> >>> C.preferences.inputs.walk_navigation. walk_speed use_gravity ...

3

Maybe better not to use a Boolean? Enable the shipped add-on: Geodesic Domes (There are other ways, but this is quick.) Create your dome: With I Inset, ('Individual' checked in its F9 Adjust Last Operation panel,) inset all its faces. Set your Pivot to 3D Cursor, and ensure the cursor is at the center of your dome. (It probably hasn't moved since the ...

2

Select your sphere, go into the Modifiers panel, give your sphere a Boolean modifier with the cone object as Object, choose the Difference option, duplicate both the sphere and the cone object to keep a copy somewhere, apply the modifier (select the modifier, keep your mouse over the modifier and CtrlA) and it will work (delete the cones otherwise you'll ...

0

Export all objects of a certain collection Pretty much straight forward. Just pass use_active_collection=True argument when calling export_scene.fbx() operator and assemble your filepath using Collection.name: import bpy C = bpy.context bpy.ops.export_scene.fbx( filepath=bpy.path.abspath("//{}.fbx".format(C.collection.name)), ...

0

After a bit of trial and error I got it working off of the older answer I linked to. It moves the selected faces up one UV tile in the active UV channel. Works with multiple objects selected # Credit to iKlsR https://blender.stackexchange.com/questions/7526/python-move-uv-for-selected-items import bpy # grab the current area original_area = bpy.context....

Top 50 recent answers are included