Skip to content

Instantly share code, notes, and snippets.

@p2or
p2or / functions.php
Created July 17, 2014 10:18
Add class to the_post_thumbnail #WP
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "grid_4 img-max attachment-post-thumbnail")); ?>
@p2or
p2or / typecheck.py
Last active May 21, 2023 19:36
TypeCheck #Blender
def typecheck(obj):
return hasattr(obj, '__iter__') and not isinstance(obj, str)
@p2or
p2or / randomGroupObject.py
Last active May 21, 2023 18:34
Select random Object in Group #Blender
import bpy
from random import choice
scene = bpy.context.scene
ob = bpy.context.object
random_group = choice(ob.users_group)
obs = random_group.objects[:]
obs.remove(ob)
@p2or
p2or / enum_GroupsInScene.py
Last active May 21, 2023 18:10
GroupsInScene #Blender
bl_info = {
"name": "tester",
"description": "",
"author": "",
"version": (0, 0, 3),
"blender": (2, 70, 0),
"location": "3D View > Toolbox",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "",
"tracker_url": "",
@p2or
p2or / blender-add-and-apply-subsurf.py
Last active May 21, 2023 18:22
Add and apply subsurf #Blender #BSE
import bpy
obj = bpy.context.object
bpy.ops.object.modifier_add(type='SUBSURF')
for mod in obj.modifiers:
if mod.type == "SUBSURF":
obj.modifiers[mod.name].levels = 1
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=mod.name)
@p2or
p2or / blender-anisotropic-shader.py
Last active May 21, 2023 18:22
Create Anisotropic Shader #Blender #BSE
# for http://blender.stackexchange.com/questions/32787/example-of-creating-and-setting-a-cycles-material-node-with-the-python-api
import bpy
# get the material
mat = bpy.data.materials['Material']
# get the nodes
nodes = mat.node_tree.nodes
# clear all nodes to start clean
@p2or
p2or / debug.css
Last active May 21, 2023 18:49
Debug CSS #WP
* {
background: #000 !important;
color: #0f0 !important;
outline: solid #f00 1px !important;
}
@p2or
p2or / blender-random-xy-animation.py
Last active May 21, 2023 18:35
Random XY anim #Blender
import bpy
import random
def random_floats(min, max, size):
return [random.uniform(min, max) for _ in range(size)]
# define a animation length
length = 10
# create a list, which contains 10 random x values
@p2or
p2or / blender-check-modifiers.py
Last active May 22, 2023 14:10
Check Modifiers #Blender #BSE
# for http://blender.stackexchange.com/questions/42080/check-if-active-object-has-a-modifier
# check for specific modifier using any()
print ([m for m in bpy.context.object.modifiers if m.type == "SUBSURF"])
# or as function
def check_modifier(obj, modifier_type):
for modifier in obj.modifiers:
if modifier.type == modifier_type:
return True
@p2or
p2or / nodes_cycles_resetnode.py
Last active May 22, 2023 14:10 — forked from zeffii/nodes_cycles_resetnode.py
Reset Node #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