Skip to content

Instantly share code, notes, and snippets.

@p2or
p2or / blender-merge-vertex-groups-jerryno.py
Created August 25, 2017 10:15
Merge-VertexGroups (jerryno) #Blender
import bpy
vgroup_A_name = "Group"
vgroup_B_name = "Group.001"
ob = bpy.context.active_object
if vgroup_A_name and vgroup_B_name in ob.vertex_groups:
vgroup = ob.vertex_groups.new(name=vgroup_A_name+"+"+vgroup_B_name)
@p2or
p2or / blender-merge-vertex-groups.py
Last active June 12, 2025 17:07
Merge Vertex Groups #Blender
import bpy
group_input = {"Group", "Group.001", "Group.002"}
ob = bpy.context.active_object
group_lookup = {g.index: g.name for g in ob.vertex_groups}
group_candidates = {n for n in group_lookup.values() if n in group_input}
# test whether all candidates components of group_lookup
if all(n in group_lookup.values() for n in group_candidates):
@p2or
p2or / Blender_Basic-UI-Template_27.py
Last active January 22, 2024 19:03
Basic-UI-Template for Blender 2.7+ #Blender #BSE
# -> For a Blender 2.8+ version, go to https://gist.github.com/p2or/2947b1aa89141caae182526a8fc2bc5a
# https://blender.stackexchange.com/q/57306/3710, https://blender.stackexchange.com/q/79779/3710
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
@p2or
p2or / illustrator-rename-selection.js
Created March 30, 2017 10:48
Rename Selection #Illustrator
function addLeadingZeros (n, length){
var str = (n > 0 ? n : -n) + "";
var zeros = "";
for (var i = length - str.length; i > 0; i--)
zeros += "0";
zeros += str;
return n >= 0 ? zeros : "-" + zeros;
}
@p2or
p2or / blender-call-bash-file.py
Last active May 21, 2023 19:44
Call Bashfile #BlenderAddon
# http://blender.stackexchange.com/q/76655/31447
import bpy
import subprocess
import os
bpy.ops.mesh.primitive_cube_add(radius=1)
bashfile = '/home/.../hello-world.sh'
os.chmod(bashfile, 0o777) # http://stackoverflow.com/a/1837896
@p2or
p2or / blender-delete-save-and-reopen.py
Last active May 21, 2023 19:14
Del Save Reopen #Blender
# http://blender.stackexchange.com/q/75310/3710
import bpy
# select all mesh objects
for o in bpy.data.objects:
if o.type == 'MESH':
o.select = True
else:
o.select = False
@p2or
p2or / blender-display-opengl-lights-on-custom-panel.py
Last active May 21, 2023 18:16
Display OpenGL-Lights on custom panel #Blender
# for http://blender.stackexchange.com/q/74766/3710
import bpy
def opengl_lamp_display(column, lamp):
split = column.split(percentage=0.1)
split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
col = split.column()
col.active = lamp.use
@p2or
p2or / blender-datablock-from-active.py
Created February 27, 2017 13:49
DataBlock from active object #Blender
import bpy
ctx = bpy.context
active_obj = ctx.active_object
selection = [o for o in ctx.selected_objects if o != active_obj]
for o in selection:
if o.type == active_obj.type:
active_obj.data = o.data
import bpy
# ---------------------------------------------------
# Collection
# ---------------------------------------------------
class MyCollectionProperty(bpy.types.PropertyGroup):
id = bpy.props.IntProperty()
name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
@p2or
p2or / blender-filebrowser-display-override.py
Last active May 21, 2023 18:07
Override File Browser Display Settings (http://blender.stackexchange.com/q/23159/3710) #Blender #BSE
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the