import bpy from mathutils import Vector s=bpy.context.scene c=next(c for c in s.collection.children if c.name.startswith('Rifle V4')) mounts=[o for o in c.objects if o.name.startswith('Integrated mount')] turret=next(o for o in c.objects if o.name.startswith('Elevation turret')) core=next(o for o in c.objects if o.name.startswith('Scope core')) rail=next(o for o in c.objects if o.name.startswith('Rail spine')) def bounds(o): pts=[o.matrix_world@Vector(p) for p in o.bound_box] return Vector(tuple(min(p[i] for p in pts) for i in range(3))),Vector(tuple(max(p[i] for p in pts) for i in range(3))) metal=mounts[0].data.materials[0] def finish(o,name): o.name=name for col in list(o.users_collection):col.objects.unlink(o) c.objects.link(o);o.data.materials.append(metal) b=o.modifiers.new('Edge bevel','BEVEL');b.width=.018;b.segments=3 o.modifiers.new('Normals','WEIGHTED_NORMAL') def box(name,loc,size): bpy.ops.mesh.primitive_cube_add(location=loc);o=bpy.context.object;o.scale=Vector(size)/2 bpy.ops.object.transform_apply(location=False,rotation=False,scale=True);finish(o,name) return o rail_lo,rail_hi=bounds(rail) for i,m in enumerate(mounts): lo,hi=bounds(m);x=(lo.x+hi.x)/2 bottom=rail_hi.z-.065;top=lo.z+.07 box('Scope rail saddle '+str(i),(x,0,(bottom+top)/2),(.36,.56,top-bottom)) for side in (-1,1): box('Rail gripping jaw',(x,side*.22,rail_hi.z-.025),(.34,.13,.19)) bpy.ops.mesh.primitive_cylinder_add(vertices=12,radius=.055,depth=.04,location=(x,side*.30,rail_hi.z+.015),rotation=(1.5707963,0,0)) finish(bpy.context.object,'Clamp screw') # Tube radius at the turret is 40/180. Connect to its actual local surface. top_core=(490-277)/180+40/180 lo,hi=bounds(turret) bottom=top_core-.06;top=lo.z+.08 bpy.ops.mesh.primitive_cylinder_add(vertices=32,radius=.18,depth=top-bottom,location=(turret.location.x,turret.location.y,(top+bottom)/2)) finish(bpy.context.object,'Turret connecting stem') box('Turret seating block',(turret.location.x,0,top_core-.025),(.42,.36,.18)) bpy.context.view_layer.update() assert top>bottom path=r'C:\roblox\hunter\3D models\sniper_reference_v6.blend' bpy.ops.wm.save_as_mainfile(filepath=path) print('Saved',path,'mounts',len(mounts),'turret connection',top-bottom)