# Tag Info

0

with a handler it may work import bpy, os ao = None def h(s): # just for testing, normally i won't use global global ao o = bpy.context.active_object if(ao != o): ao = o print(ao) if ao.name == "Cam Small": return None bpy.app.handlers.depsgraph_update_post.append(h) but that doesn't really respond to the goal ...

0

In Blender 2.80, I've had some success with something simpler that previous @johnzero7's solution : collection = bpy.data.collections.new('My Collection') bpy.context.scene.collection.children.link(collection) # NOTE the use of 'collection.name' to account for potential automatic renaming layer_collection = bpy.context.view_layer.layer_collection.children[...

1

This can be solved by checking whether the timer has been set before. Unfortunately the example has a little confusing mistake. self._timer = wm.event_timer_add(0.1, window=context.window) does not assign a value to the class attribute _timer as declared at the beginning of the class. Instead it creates an instance attribute named _timer. You can see this by ...

0

Here is a proposal for the first question, without using the matrix conversion (not sure why it's necessary there?). Does it work for you? import bpy from bpy.props import FloatProperty from mathutils import Vector, Matrix, Quaternion, Euler from math import degrees, radians class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object ...

1

The following example shows how to create multiple operators each with their specific function. It only shows three buttons, but the concept remains the same for an arbitrary number of buttons and their underlying operators. The panel is created in the sidebar of the 3D View which can be opened with N. I hope I haven't misunderstood what you're trying to ...

0

Found the solution! After completing the rendering of the scene you should free the bake of the objects by using: bpy.ops.ptcache.free_bake_all() Hope that help to other ones as well.

1

You need to indent your call to bpy.ops.wm.modal_test_operator() so it will only be executed when the code as run as a script, which is the case when __name__ == "__main__". Otherwise you're trying to access blend data when the add-on isn't registered, which results in the exception you're seeing. For more information about this topic take a look at this ...

0

The error message tells you that the error is in line 47 which is: for obj in scene.objects: You haven't declared and assigned a variable named scene, so the correct code would be: for obj in bpy.context.scene.objects: The same mistake happens in line 68 as well. Alternatively you can also create a variable named scene and assign bpy.context.scene to it. ...

1

The script below retrieves the home directory and generates the path to the desktop. If the project has been saved before, it adds the name as prefix. import bpy import os from pathlib import Path from sys import platform home_dir = str(Path.home()) if platform == 'linux' or platform == 'win32' or platform == 'darwin': desktop_dir = os.path.join(...

2

The good answer stays for hatinacat2000. Though, the implementation could be optimized from the code given in the question, and stay in $O(n^3)$, but does not need to allocate combinations (and that can spare a lot of memory if there are many points). It considers parallel planes as we progressively check best plane containing first point, then second ...

1

Blender 2.80 In order to activate the selection of edge marks you first need to access the Freestyle settings. These settings can be found in the view layer in Blender 2.80. Assuming your view layer is called "View Layer" you can access the settings using the following code: freestyle_settings = bpy.context.scene.view_layers["View Layer"]....

0

You can load the default startup file using bpy.ops.wm.read_homefile(). This operator also allows you to load application templates if you use the optional app_template argument. Be aware that the current .blend project file will not be saved automatically, meaning all unsaved state will be lost. The problem with loading the default startup file or any ...

0

A little later, I reported to the developers and they fixed this error. T70714 This question has ceased to be relevant.

0

I am just going to assume this error is just a bug or something. I worked around it by creating a new file, uploaded my reference image and sculpted the object there, and then appended it to my donut file. I hope this helps anyone struggling with the same issue.

0

Adding to the answer of DB3D: Assuming that panel for the preset uses preset_operator = "script.execute_preset" the selected preset is indeed stored in bl_label. This can be seen in class ExecutePreset(Operator) in the presets.py where the label is changed to the most recent selection when the operator is executed. # change the menu title to the most ...

0

Thanks to @AFWS print(bpy.types.CYCLES_PT_integrator_presets.bl_label) active preset is in fact the name of the bl_label

0

For blender 2.8 try this def withinMesh(x,y,z,mesh): axes = [ mathutils.Vector((1,0,0)) , mathutils.Vector((0,1,0)), mathutils.Vector((0,0,1)) ] point = mathutils.Vector((x,y,z)) outside = False mat = mesh.matrix_world.copy() mat.invert() for axis in axes: orig = mat @ point count = 0 while True: ...

1

obj = bpy.context.active_object for index in range(0, len(obj.material_slots.keys())): obj.active_material_index = index if "." in obj.active_material.name: mat = obj.active_material.name[:-4] bpy.data.materials.remove(obj.active_material) obj.data.materials[index] = bpy.data.materials[mat] This work, I kind of ...

0

First of all you'll need to make sure, that Atom knows how to lint and autocomplete python-code (there should be plenty of packages to achieve that). Test your auto-completion and package access with common packages (e.g. os). Make sure it works as desired. If so, the only thing left to do is to get Blender into your python environment. You can either ...

1

Your code performs infinite recursions. For every call to moveObj you're creating a thread that in itself calls moveObj again. A solution for your goal is to use a modal operator in combination with a timer to execute a function every x seconds. An example for this can be found in operator_modal_timer.py

3

obj.name gives you the object name. obj.data.name gives you mesh name. And yes, AFAIK there can be only one mesh per object. However there can be multiple objects sharing the same mesh data block.

0

The difference between a copied object and an instance is that the copied object is a separate entity that can have its properties, materials, modifiers etc. adjusted without affecting the object it was copied from. Instances of an object are practically identical except for their location, scale and rotation. Changes to the object affect all instances of it....

0

Another way you could do it is: def render_scene(self, file_name): bpy.data.scenes[0].render.filepath = os.path.join(self.output_path, file_name) bpy.ops.ptcache.bake_all() bpy.ops.render.render(animation=True)

0

Found the solution! since using third party (Blender) import sys sys.path.insert(0, <path_to_repo>) is needed to set the environmental variables

0

An example that should work with Blender 2.80: The directory: folder | -> main.py | -> scripts -> __init__.py -> hello.py scripts/__init__.py: from scripts.hello import * scripts/hello.py: def hello(): print('Hi') main.py import bpy import sys if __name__ == '__main__': sys.path.append('') import scripts scripts....

0

Use some kind of quick bounding box culling like this(javascript, but should be easy enough to adapt) to eliminate objects that cannot overlap. Beware that Blender objects' provided bounding box is in object space, so may not be axis aligned in world space. You will need to convert it to world space and then generate a new bounding box of that bounding box ...

0

This is an example based upon batFINGER's link that uses a vertex index. import bpy import bmesh context = bpy.context mesh_obs = [o for o in context.selected_objects if o.type == 'MESH'] bm = bmesh.new() for ob in mesh_obs: me = ob.data bm.from_mesh(me) bm.verts.ensure_lookup_table() bm.verts.remove(bm.verts[0]) bm.to_mesh(me) ...

3

There is no "simple" way to do anything in numerical analysis. However, the tasks can be laid out straightforwardly. EDIT: This idea is a brain-fart because it doesn't distinguish parallel planes. The Internet must never forget though. Pile on, people. How about this: generate an array of normalized normal vectors (not vectors in the dynamic array sense; ...

1

bone.layers is an array of 32 boolean values tells you whether the bone is present on each of the 32 layers. So you could add the line: bone.layer[8] = True for bone in bpy.context.active_object.pose.bones[:]: if bone.name in ListOfBoneNames: bone.layer[8] = True #put that bone into bone layer 8 #could also remove the bone from other ...

0

Think you need to flush your selection. This code works, slightly different from yours as it uses bmesh.from_edit_mesh, but if it gets the job done then maybe okay: import bpy import bmesh context = bpy.context obj = context.edit_object me = obj.data bm = bmesh.from_edit_mesh(me) bm.select_mode = {'VERT'} for v in bm.verts: v.select = ( v.co.x > 0 )...

0

I'm just doing my duty here. Quick answer that works in 2.8: objectToSelect = bpy.data.objects["objectName"] objectToSelect.select_set(True) bpy.context.view_layer.objects.active = objectToSelect You need that last line. Without it I couldn't switch into edit mode. I got the answer here. I wanted to post it here, which is actually the question that ...

2

Add-ons can do per-file initialisation, if the add-on has some kind of panel in the UI somewhere. You may notice various panels in Blender's UI have checkboxes next to the panel title. This is can be because they don't want to be active unless specifically turned on, but it can also be because they want to do some setup before being used: This can be ...

2

There are multiple issues with your script: The indentation is incorrect. Code that belongs into your T_M function isn't indented by four spaces, which results in the code being executed even though the functions wasn't called. Similarly the functions that should be part of the class aren't indented, e.g. the execute function for Test_MaterialOP. The ...

1

You could do it like this: obj = bpy.context.object # Select the active object. mat = bpy.data.materials.new(name='Material') # Create a material. # Settings for the material go here. obj.data.materials.append(mat) # Assign the new material.

0

You are using multiple selection modes. Change line 8 of your code to prevent vertex selection bm.select_mode = {'EDGE'} Note the use of = instead of |= to force edge selection only. Without a blend file to test on I'm not sure of the gotchas but the following is a quick and dirty way to do what I believe you are trying to achieve: import bpy bpy.ops....

-1

If you don't want curved surfaces then points are on a plane when one of their (x,y,z) coords is the same e.g z (a horizontal plane). When a linear function f(x)=ax+b is involved the plane is rotated/sheared.

0

Is this what you want to select? for v in bm.verts: v.select = not v.is_boundary

1

Or you could also do: import bpy import bmesh selected_verts = [v for v in bpy.context.active_object.data.vertices if v.select] count = len(selected_verts) print(count) `

0

import bpy import bmesh mode = bpy.context.active_object.mode selectedVerts = [v for v in bpy.context.active_object.data.vertices if v.select] count=0 for v in selectedVerts: count+=1 print(count) bpy.ops.object.mode_set(mode=mode)

2

The way you could do this is by trying for almost all combinations of three points, choose the plane which contains the most points. It will run in $O(n^4)$ for $n$ points.

1

I actually do the opposite to @RLGUY's solution, by using the files in the 'addons' directory in my Blender 'home' directory (eg, C:\Users\Rich\AppData\Roaming\Blender Foundation\Blender\2.80\scripts) to edit the development files and then simply restart Blender to ensure I get a clean re-load of the add-on files. I use GIT for source control and this comes ...

0

I assume you are using Blender 2.79, it may not work. But in Blender 2.80, this is how I would do: if __name__ == "__main__": bpy.ops.screen.animation_play() write_image() Does the issue persist with Blender 2.80?

1

Yes, of course this can be done. If you have an add-on with its folder and __init__.py inside it, if you have other files like file.py in the same folder you just import stuff from it like this: from .file import Some_stuff Just open [Blender's installation folder]\[version]\scripts\addons\ and see how it's done with any of the add-ons in the folders there....

0

Depending on what the rest of the code does (and whether it handles any exceptions) you could simply raise an exception with : raise Exception(“I’ve just triggered termination of my script”) If the code doesn’t specifically handle exceptions then this will terminate the processing and Blender will report the message raised in the exception. Obviously, you ...

0

When I tried a similar method, the def function could not be specified correctly in register. I learned how to use "lambda s, c: s.layout.separator ()". Using lambda in register, simply defining an empty function and emptying the menu. In addition, it was solved by adding the function you want to add with prepend. ´´´Python import bpy def ...

0

bpy.types.TOPBAR_HT_upper_bar.draw expects a draw function. Here is an example for how to replace the built-in draw function with your own: import bpy def draw_function(self): self.layout.label(text="New Custom Menu") bpy.types.TOPBAR_HT_upper_bar.draw = draw_function

1

bpy.data.cameras.remove(bpy.data.cameras["Camera"]) This will remove the camera data. Does this answer your question?

0

For 2.8 When I was running code, console showed me some problems, so I deleted the active objects name for the path of the key ( line 36 ), because whenever you copy path manually in 2.8 from the value you will not have to include active objects name ( just copying shape key value ) import bpy selected_obj = bpy.context.selected_objects active_obj = bpy....

1

You can enable Indirect Only for the currently active collection (as indicated in the outliner) by using: bpy.context.view_layer.active_layer_collection.indirect_only = True

3

mathutils now uses the PEP 465 binary operator for multiplying matrices. matrix_final = obj.matrix_world * pose_bone.matrix becomes matrix_final = obj.matrix_world @ pose_bone.matrix Since 2.8 object are now stored in Collections, so : context.scene.objects.link(obj_empty) becomes bpy.data.collections['Collection'].objects.link(obj_empty) Here is the ...

Top 50 recent answers are included