New answers tagged

5

As you noticed, bpy.context.object points to the active object, regardless of the variable in your for loop. In your last line you are iterating over all selected objects, but you are not actually using the iteration variable afterwards, cube. Replace the last line with print(cube.scale[0])


1

I had to go through several other issues to pin this down, including another question on stack Overflow, where I was not getting much help. I'll include what I can here. That'll be more than most people want to read, but if you have this problem, skim it because you might find helpful stuff in here. The bottom line is that I was setting PYTHONPATH in ....


3

Update method on pointer property Not sure if this is a bit of an XY Problem In as much as agree that invoking the filebrowser is a way to select the filepath before executing the operator it is generally displaying other options (often for import export) while it runs modally. To simply select a filepath before running could achieve same with def foo(self,...


0

So, when you generate objects, you made them without normals. I don't want to say, that they have no normals completely, because mesh can't be without normals. What I see, that all normals are rotated in the same vector, so your objects look completely flat: But what causes the jittering in colors? This vector is different from one object to another. This ...


1

Easily checked. The type of region available to each of the area types is probably in the docs somewhere, however it is easily checked using the python console. With a 3d view area as the variable area (C.screens.areas[3] in this example) >>> area bpy.data.screens['Scripting.001']...Area >>> area.type 'VIEW_3D' >>> for region in ...


3

From the camera view frame. bpy: How do you find the corners of a camera frustum? A camera points in the -Z direction. For a perspective camera can find the vectors of the origin to the frustum and if and where they intersect with the XY plane. Test script. Have kept it simple. Uses the scene camera, finds the frustum, adds a cube on XY plane given image (0,...


2

Just use an Emission shader. This will emit the intensity of the surface without responding to any surrounding light sources so will produce a pure "unshaded" colour. Related: Node for setting render colour, regardless of lighting


1

The copy function can be used on the node tree as well. The copy function returns the copied node group, so it can be used replace the original group with the single user copy: original_group = bpy.context.objects['Object'].material_slots['Material'].material.node_tree.nodes['Baking_node'].node_tree single_user_group = original_group.copy() original_group = ...


4

Im afraid it's not possible without modifications. As stated in the manual, the workbench purpose is to provide a fast visual output for animators. The Workbench Engine is a render engine optimized for fast rendering during modeling and animation preview. It is not intended to be a render engine that will render final images for a project. Its primary task ...


2

No, you can't. But take a look on this add-on: https://gumroad.com/l/simpletabs https://blendermarket.com/products/simple-tabs It can reorder tabs and group several tabs into one. So you can save a lot of space putting several add-ons (that you don't often use) into one tab, or group add-ons by functionality.


4

Bmesh script. With a single boundary edge selected in edit mode, the LHS of question images can be achieved calling bpy.ops.mesh.loop_multi_select() directly from the python console. >>> bpy.ops.mesh.loop_multi_select( loop_multi_select() bpy.ops.mesh.loop_multi_select(ring=False) Select a loop of connected edges by connection type >>> bpy....


0

I found a solution for myself. However, it regrettably does use bpy.ops. If anyone has a solution which does not use bpy.ops I'd gladly take a look at that answer. Here is the blend file for anyone who wants to take a look.


1

Numpy Version with aspect ratio This question came up wrt How to rotate UV and preserve the correct aspect ratio? Thought I would also post here. Using numpy and foreach_get and foreach_set will be noticably quicker for large meshes. It is quite likely numpy didn't ship with blender when question was asked / answered. Deals with aspect ratio. Code. import ...


3

Clearly the UV editor uses the aspect ratio. Closing the image in the UV editor on LHS demonstrates that the UV editor is using the aspect ratio of the image when rotating. The LHS rotation result is equivalent to running script result in question, or with unit aspect ratio below. Instead of our normal 2D rotation matrix, $$R=\left[ \begin{array}{ccc} \...


1

The solution was very simple at the end. Everything what needs to be done with the data which was loaded by the ImportHelper should be part of the execute method of this class. The invoke method (in my above script) was not needed at the end: class ImportFBXData(Operator, ImportHelper): bl_idname = "import_fbx.read_data" bl_label = "...


-1

Well, I'm not sure what exactly it is you want, so i will just make a guess. Go into your object properties -> viewport display and enable "Name". This will show the objects name in the viewport.


0

So the method I ended up using (for now) is a bit unexpected. I use the method that's described in the question above to select all boundary edges. After that I use Split -> Faces by edges. What this does is "unweld" ot "unmerge" the selected parts (which in this case are the boundary edges of all the UV islands). Then, when these are ...


2

Mesh 'n Freestyle Here is a very quick'n'dirty proof of concept. Make a mesh from our mesh of interest's UV's as demonstrated here How to get data and edit it on UV map edges? . For this one have used numpy to quickly make the mesh. Moved the origin to (0.5, 0.5). Removed doubles and marked boundary edges selected with bmesh, then as freestyle edges. How ...


2

Some alternatives. I am not sure what you ask is possible without some serious dicking around. If these are bundled addons can simply enable and disable them as required in your code https://blender.stackexchange.com/a/58208/15543 In that you can enable an addon when required eg https://blender.stackexchange.com/a/189435/15543 Use a different Preferences ...


1

As a variant of a solution. I could suggest adding history before all the code. But I'm pretty sure this is a bug in Blender's sculpt mode. if context.mode != 'OBJECT': bpy.ops.ed.undo_push()


-1

I use .keys() objects = bpy.context.scene.objects.keys() if not 'Cube' in objects: print('cube doesn't exist!') elif 'Cube' in objects: print('Cube exists!!') the same as dict.keys() in python dict returns a list of the objects names


0

Im not entirely sure on what youre trying to do but I'm assuming you want to import a 3d file and move it to a specific location and rotate it? I think your problem may be: MeshObject = ob_for_convert.to_mesh() What I usually use is: block = bpy.context.selected_objects[0] Then we can move the location and rotation: block.location = (1,1,1) block....


3

Here is perhaps a solution, using the closest_point_on_mesh operation. I just enhanced to test the extreme vertices (bound_box) on the object being placed to be sure that it is placed completely within the floor bounds. I tested with on odd shaped floor (not just a rectangle plane). Note that this solution assumes that the floor has many vertices (...


1

I would recommend looking at other forums on python for how to read audio files. This is not possible with blender’s normal API usage. You would need to go through Python. Pygame. I believe that pygame.mixer can return a sound as an array which will give you the individual samples. This is what you need. Wave. A module for reading the data in wave audio ...


0

1_conscience_0_dimen Answered me a solution. Basically the layout work differently but we can call the menu in this different way to keep the right layout. He posted me this script that show the behaviour. You can see it in the link above too import bpy ###Panel class PANEL_PT_Menu(bpy.types.Panel): bl_label = "panel menu" bl_space_type = ...


0

Maybe for objects in door.children since you're parenting them? Yeah it could be cool to use magic method looping over children


2

My suggestion is don't use it. Can see reason for confusion, have personally never used the scale value in the operator, (fortunately because yeah it's bloody confusing) Speculate there could be some legacy nature about it. Crunch any operator into the python console auto complete Tab will show defaults of an operator >>> bpy.ops.mesh.pri<Tab&...


2

Look at the mesh coordinates. The unmodified dimensions of the mesh can be obtained from the mesh. import bpy import numpy as np ob = bpy.context.object me = ob.data coords = np.empty(3 * len(me.vertices)) me.vertices.foreach_get("co", coords) x, y, z = coords.reshape((-1, 3)).T mesh_dim = ( x.max() - x.min(), y.max() - y.min(), ...


6

Via Select Box Operator Example in blender version 2.91,2, after running script, adding Box Select operator with range options (arbitrarily labelled Select UV Image Bounds) to UV editors select menu. AFAICT the select box operator uses normalized image 0-1 coordinates in the UV editor, as does the cursor, totally debunking this assertion in question. ...


4

Bmesh script. Here is but one of may ways could approach this. Rib n Bridge Make growth_segments cirlcles all with segments segments. Each has a radius in range (min_radius, max_radius) and the the next is in the range of (min_growth, max_growth) above. A translation matrix, using the accumulative height is used to place each successive circle. Each ...


5

Unfortunately the glTF exporter does not recognize the setup that "Import Images as Planes" uses for a "Shadeless" material, which looks like However if you delete the group node, it can recognize that graph as "Shadeless" and should be able to export it.


0

Alright, I found the solution with some help of the answer of batFINGER here. There's surprisingly little information on the internet about manipulating face normals at the vertex positions, confusingly called 'split normals' or 'loop normals'. To work with split normals with python you first need to use the method calc_normals_split() on the mesh or else ...


1

In newer versions of Blender you can use (while in Edit Mode): bpy.context.active_object.data.total_vert_sel bpy.context.active_object.data.total_edge_sel bpy.context.active_object.data.total_face_sel See: https://docs.blender.org/api/current/bpy.types.Mesh.html?highlight=_sel#bpy.types.Mesh.total_edge_sel Also count_selected_items() returns the number of ...


5

Add to sys.modules Among other ways to make fake modules, can simply add it to sys.modules >>> import sys >>> sys.modules["function"] = bpy.data.texts['function.py'].as_module() >>> from function import function >>> function() hello Have a good link re fake modules and namespaces, will look for it. https://...


5

Via mathutils.Matrix.Rotation constructor. Given an axis angle rotation provides just that, can make a matrix from the components. Matrix.Rotation(angle, size, axis) >>> q Quaternion((0.44383183121681213, -0.3263395428657532, 0.8345092535018921, 0.010497181676328182)) >>> axis, angle = q.to_axis_angle() >>> R = Matrix.Rotation(...


0

I managed to solve the issue and get a (usually) reliable effect. I ended up moving the parts of the driver that handled assigning previous locations and calculating acceleration into a frame change handler, similar to how this answer does. I'll attach the example blend file to the end of this answer. The following script is the main component of this effect:...


0

The presented error seems to have less to do with the blender API, and more to do incorrectly initializing the python object. You need to use the super function to properly call the parent class’s init method, but you don’t need it here anyway since you’re not changing the init method at all. Just remove that redefinition of the init method. There may be ...


2

Similar to Import STL via python, you can use the ImportHelper class if you'd like to import and modify objects. Have a look into the Operator File Import template that comes with Blender. In order to join the objects, see @batFINGERs answer on: How to join objects with Python? How to import multiple objects using the file browser, you can find here: How to ...


4

Property definitions saved in blender rna. When we define a prop with bpy.props the methods are akin to python's property method, extended to save the details in the blend files rna. (From the geneticists mumbo jumbo) All the things we define in the definition funcion, in this case FloatVectorProperty are stored here. The value when set is stored as a ...


2

The naive solution is easy enough to do in Python: from bmesh import from_edit_mesh import bpy def select4vertTop(k: int = 8) -> None: bpy.ops.object.mode_set(mode='EDIT') mesh = from_edit_mesh(bpy.context.object.data) # Define a helper function that we calculate distance, using Euclidean distance. get_distance = lambda v: v.co.x ** 2 + ...


5

KDTree and the objects bounding box. Each object has an axis aligned bounding box giving the 8 coordinates of the cuboid the object fits into. If a cuboid is perfectly axis aligned the bounding box corner coordinates exactly match those of the corner verts. A KDTree can be used to quickly find the closest element to a coordinate Putting it together in a ...


2

First, you' have to know where the font-files are located in your system. You can find this location by changing manually a font. On my Windows machine, this is: C:\WINDOWS\Fonts\ARIAL.TTF for the Arial font. Then paste and run run the followig code in the Text Editor of the Scripting workspace to assign the Arial font to the active (selected) strip. import ...


2

Add 'INSTANCED' to panel options Edit Credit to @Nilson (finally twigged) How to hide a panel that appears twice? I found the solution .. and it was very simple. Just use: bl_options = {"INSTANCED"}. The popover menu is just an instance of the panel If the 'INSTANCED' option is added to the panels bl_options the panel is not drawn directly in ...


1

Make a lookup table. In going the other way can look at all objects in blend and from their animation data check all actions either assigned directly or via the NLA. For example sake have used a defaultdict assigned to a set. Iterated over all objects and added all assoc. actions to set. import bpy from collections import defaultdict actions = defaultdict(...


3

Is it as simple as it could be?. A TL;DR comment turned into answer: Doesn't crash for me... but does throw errors. Some of the issues as I see them. Sure it's a simple little addon, but.. appears to be some added and IMO unnecessary complexity added too. (bling). Is there really any need to type hint the usual suspects and familiar arguments of self, ...


3

A way for Ubuntu Having horrible issues building blender currently, so have gone thru the motions of setting up virtual environments for freshly downloaded 2.91.2 and 2.92.0 Have both in vers folder Note commands shown below are <prompt> $ <command> shitbox:~/blender/vers$ ls blender-2.91.2-linux64 blender-2.92.0rc-linux64 renamed the python ...


0

To understand what the numbers represents you need to consider the context in which they are stated. If you wish to avoid coding - you may want to try and error. Modify values and observe the result. copy the script. Use the copy and don't register it. Change one value at the time. Some of these values are not related to Blender but the OpenCV - the keymaps ...


7

Have a look into the python templates that come along with Blender. There is an Operator Mesh UV template you can modify to your needs. Based on that, all you would have to figure out is how to set the select state of each UV vertex you're iterating on, by searching in the docs. import bpy import bmesh def main(context): obj = context.active_object ...


1

I found the reason! We were setting the tile size to the size of the map. According to the comment next to the code it was an optimisation recommended on Blender forums, and indeed it was way faster than setting a small tile size on 2.83. On 2.90 however, it was sluggish as hell. Setting a 32 tile size made things much better (it's even a wee bit faster than ...


2

Its running modal The file browser as noted in question code when invoked is running modally. print("execute", self.filepath) in your execute method where you set the class property, will notice in output No file selected execute some/file/path because the filebrowser has been invoked and is running modally, the last print in script is executed ...


Top 50 recent answers are included