User
Write something
Coffee Hangout is happening in 14 days
Capstone Project for Part 1
I made a script that clears the scene if there was anything superfluous), and adds two types of trees. With each click of the script, the trees are positioned differently, as well as their height. Script and screen import bpy import random green_plane = bpy.data.materials.new(name= "Trava") green_plane.diffuse_color = [0, 0.45, 0, 1] green_tree = bpy.data.materials.new(name= "Listva") green_tree.diffuse_color = [0, 0.7, 0, 1] brown_tree = bpy.data.materials.new(name= "Stvol") brown_tree.diffuse_color = [0.2, 0.1, 0, 1] green_black = bpy.data.materials.new(name= "Elka") green_black.diffuse_color = [0, 0.2, 0, 1] def clean_scene(): bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete() def add_plane(): bpy.ops.mesh.primitive_plane_add() plane = bpy.context.active_object plane.scale.x = 20 plane.scale.y = 20 plane.data.materials.append(green_plane) def add_tree(): for i in range(10): x = random.randint(-19, 19) y = random.randint(-19, 19) height = random.randint(4, 6) bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, location = (x,y, height / 2), depth = height) cyl = bpy.context.active_object cyl.data.materials.append(brown_tree) bpy.ops.mesh.primitive_uv_sphere_add(location = (x,y, height), radius = 3) uv = bpy.context.active_object uv.data.materials.append(green_tree) for i in range(10): x = random.randint(-19, 19) y = random.randint(-19, 19) height = random.randint(4, 6) bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, location = (x,y, height / 2), depth = height) cyl = bpy.context.active_object cyl.data.materials.append(brown_tree) bpy.ops.mesh.primitive_cone_add(location = (x,y, height), depth = height,radius1= 2) cone = bpy.context.active_object
Capstone Project for Part 1
Part 2 section 3 Quiz and Exercise...on the BaseMesh Class
Hi all, in Part 2 section 3 Quiz and Exercise...on the BaseMesh Class...the add_wireframe_mod() method is reading the wireframe_name attribute, but it always seems to be "None". I added a bunch of print statements to see what was getting passed and everytime it is "None". Even if the mesh already has multiple wireframe modifier on it. BaseMesh class seems to be overwriting the name...so it keeps adding wireframes.
Struggles in duplicating an object with a Follow Path constraint
In my short film about fungi, I need lots of spores randomly floating around the scene. So I made one original spore with a Follow Path constraint targeting a Bezier curve. This would allow it to be animated using the Offset Factor in the constraint panel. I thought I’d then make copies by writing a script to duplicate the original spore. Not so easy! It took forever to get it right. One each try, the spore copy was displaced somewhere on the screen and not lined up at the start of the curve copy as it should be. This is what I had to do (also documented in the script file): Steps: 1. Select the spore and flight path for duplication 2. Duplicate the spore and flight path objects 3. Disable the Follow Path constraint 4. Centre copied spores at world origin (0, 0, 0) 5. Move the duplicates to a new location 6. Enable the Follow Path constraint on the copied spore I’ve attached the blend file and the python script. The spores are now ready for animation. Next step - maybe I’ll try to animate using a script. I’m using Blender 4.5.
Struggles in duplicating an object with a Follow Path constraint
cleanup before running experimental code / after errors
Hi, the last time I got time (years ago) for blender & python blender often crashed, until I started to use cleanup functions at the beginning of every code. Today I updated the functions. Blender still sometimes crashes - but in the most cases the problem is "me" and not blender ... Any suggestions? I try to make alle my code pep 8 (pretty new to me) conform because I have an absolute naming-chaos in my hoarded function .... Yes - I know "_obj" e.g. in the function "remove_all_objects()" is not pep 8 conform - but it's a kind of personal "flavor" I like. If I see _obj, I know without doubt that it is something not from die def of the function. def remove_all_objects(): print("--- Removing all objects ---") for _obj in list(bpy.data.objects): bpy.data.objects.remove(_obj, do_unlink=True)
Replaces an expression in all Blender Text data-blocks
Hi, I just created (with a lot of help from Gemini!) a function to replace an expression in multiple text blocks. Seems to work - quite well. I often change something in a function because I am constantly learning new and better ways to do something in Python. Maybe you find the function useful too - or have suggestions for improvements? replace_text_with_exclusion( search_string = "export_object_as_stl", replace_string = "export_obj_as_stl", exclude_names = ["this_text_block", "do_not_touch_either"])
2
0
1-25 of 25
CG Python Academy (Free)
skool.com/cgpython
3D artists learning Blender Python.
Leaderboard (30-day)
Powered by