Skip to content

Instantly share code, notes, and snippets.

@jaforsgren
jaforsgren / keybase.md
Last active February 1, 2021 08:12
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@jaforsgren
jaforsgren / pytest_fixture_with_report.py
Created April 16, 2019 11:24
pytest fixture report ion failiure
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# set a report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)
@jaforsgren
jaforsgren / split_geometry_primitives.py
Created March 28, 2019 14:35
split primitive islands into separate primitives
old_primitive = { 'material': '2.mat', 'verts': [1, 4, 7, 7, 8, 9, 9, 0, 0]}
tris = [old_primitive['verts'][i:i+3] for i in range(0, len(old_primitive['verts']), 3)]
new_primitives = {}
primitive_id = 0
new_element = {'triangles':[]}
for i, tri in enumerate(tris):
prev = [item for sublist in tris[:i] for item in sublist]
if any(v in prev for v in tri):
new_primitives[primitive_id] = new_element
@jaforsgren
jaforsgren / traverseMaterials.ms
Created March 21, 2019 12:02
traverses materials, applies fix_func on vraymtl material
fn traverseMaterials materialList fix_func = (
/*traverses materials, applies fix_func on vraymtl materials */
for mat in materialList do(
if mat != undefined then(
if (classof mat) == vraymtl then(
fix_func(mat)
)
else if (classof mat) == multimaterial then(
traverseMaterials mat.materialList fix_func
)
@jaforsgren
jaforsgren / regex_example.py
Created January 3, 2019 12:11
python rregex example
import re
s = "MAT00001V1_materialName"
result = re.search('MAT\d+V\d+', s)
if result is not None:
l = result.group(0)
print(l)
@jaforsgren
jaforsgren / repath.ms
Created September 27, 2018 07:50
repoints paths to the location of the max files
-- swiped from https://forums.cgsociety.org/t/getting-a-list-of-scene-bitmap-paths/1545447/8
gc() -- just for this example, to make sure everything is nice and clean
-- find the scene root. The rootnode, medit, etc are references off this scene root
sceneroot = (for r in (refs.dependents rootnode) where (classof r == Scene) collect r)[1]
-- collect all the assets
origAssets = for i = 1 to AssetManager.GetNumAssets() collect (AssetManager.GetAssetByIndex i)
@jaforsgren
jaforsgren / getKeyValues.py
Created July 3, 2018 05:56
get key/value from nested dict
def getKeyValues(dictionary, key, entryList=[]):
pList = []
for entry in dictionary:
if isinstance(dictionary[entry],list):
for i in dictionary[entry]:
pList += getKeyValues(i,key)
else:
if isinstance(dictionary[entry],list):
pList += getKeyValues(dictionary[entry],key)
if isinstance(dictionary[entry],dict):
def createLayerShuffles(node):
# thanks to Peter Hartwig for this code
channels = node.channels()
layers = list( set([c.split('.')[0] for c in channels]) )
for layer in layers:
if not "Obj" in layer:
if not "MtlID" in layer:
if "Raw" in layer or "DiffuseFilter" in layer:
fn findhead obj =
(
if (isGroupHead obj)
then (return obj)
else (if (isGroupMember obj) then (findhead (obj.parent)) else (return undefined))
)
@jaforsgren
jaforsgren / Nukebatchthroughfolder.py
Created October 3, 2017 12:20
Nuke batch through folder
import os
renderDir = r"//DISKSTATION/Projects/Vikingbad/Komponentbibliotek/PreviewStudio/RenderOuput/20170927/20171002_Renders_pre/"
outputDir = r"//DISKSTATION/Projects/Vikingbad/Komponentbibliotek/PreviewStudio/RenderOuput/20170927/jpg/"
readNode = nuke.toNode('Read2')
writeNode = nuke.toNode('Write1')
for render in os.listdir(renderDir):
readNode.knob('file').setValue(renderDir+render)
print readNode.knob('file').value()