Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
taikomatsu / gist:944e3a62ce638509f6fc
Created July 2, 2015 15:05
Get all (readable) attributes value and set it to another (only settable)
from pymel.core import *
# get all (readable) attributes value
o = selected()[0]
attrs = {}
for a in listAttr(o):
try:
v = o.attr(a).get()
attrs[a] = v
except Exception, e:
print e
@taikomatsu
taikomatsu / compare_pymel_openmaya.py
Created July 3, 2015 09:03
pymel vs OpenMaya speed test
# this test executed on 80,000 vertices sphere and 6 faces box
from pymel.core import *
from time import time
from maya import OpenMaya
def calc_time(f):
def fn(*args, **kwargs):
s = time()
r = f(*args, **kwargs)
@taikomatsu
taikomatsu / gist:193b371c1670d2ca8264
Created July 4, 2015 18:54
Copy all textures in current scene
from pymel.core import *
import shutil
copydir = r'z:\path\to\copy'
for o in ls(type='file'):
path = o.fileTextureName.get()
shutil.copy(path, copydir)
print('# Done')
@taikomatsu
taikomatsu / get_angle_difference_from_z_to_selected_edge.py
Last active August 29, 2015 14:25
get angle(degree) difference from z axis to selected edge.
from pymel.core import *
# 確実にエッジを取得したいのでfilterExpandを使用。
e = filterExpand(sm=32)[0]
# 更にfilterExpandを使用するとls -flをした時と同様に要素が1つずつ確実に返ってくる。
# edgeの両端のvertexの場合、頂点番号がつながっているとそのまま1まとまりで返されたりする。
# なので念のため再度filterExpandに渡してデータにエラーがないようにしている。
# filterExpandでは文字列を返してくるため最後にPyNodeを使ってpymelオブジェクトに変換。
v = [PyNode(v) for v in filterExpand(polyListComponentConversion(e, fromEdge=True, toVertex=True), sm=31)]
space = 'world'
# normal()はnormalizeされたデータのコピーを返す。
@taikomatsu
taikomatsu / evaluate_tcl_expression.py
Last active August 6, 2019 09:30
Evaluate Tcl Expression
# ReadのfileでTcl書式のExpressionが使われていた場合に
# パスを展開して取り出す方法
import nuke
reads = [o for o in nuke.selectedNodes() if o.Class() == 'Read']
for o in reads:
filepath = o.knob('file').getValue()
print nuke.tcl('subst', filepath)
@taikomatsu
taikomatsu / evaluate_tcl_expression2.py
Last active September 12, 2015 15:07
Evaluate Tcl Expression 2
# ReadのfileでTcl書式のExpressionが使われていた場合に
# パスを展開して取り出す方法 改良版
# ※この方法だと%04dとかも一緒に展開される模様
import nuke
for o in nuke.selectedNodes('Read'):
filepath = o['file'].evaluate()
print(filepath)
@taikomatsu
taikomatsu / automatic_playblast.py
Last active September 16, 2015 14:01
Playblast Automater
# Mayaで大量のシーンのplayblastを一斉に取りたい時用のスクリプト。
# 事前に取得したシーンファイル名をムービー保存ディレクトリと一緒に渡すとプレイブラスト開始。
# このスクリプトではフォーカスしたいオブジェクトを記述すればそれにフォーカスしてプレイブラストをするものの、
# カメラの固定やジョイントの表示をOFFにしたいなどあれこれやりたいことはあると思うので、
# その場合はviewport settingsの下辺りに追加してやればOKのはず。
from pymel.core import *
import os
import os.path
@taikomatsu
taikomatsu / export_seq_alembic.py
Last active October 28, 2015 09:02
Export sequential alembic file
# Alembicを全体で1ファイルではなく各フレームごとに出力したい場合に使用
# 以下では1-100Fまでを出力
# start, endの値を書き換えてデータを出力しているので、ファイル名に$Fなどが入っていないとだめ
abc = hou.node('/obj/obj_name/rop_alembic1')
for i in range(100):
f = i + 1
abc.parm('f1').set(f)
abc.parm('f2').set(f)
abc.parm('execute').pressButton()
@taikomatsu
taikomatsu / get_forceobjects.py
Created November 19, 2015 07:26
Get objects specified in "Force Objects" on ROP by hom
root = hou.node('/')
rop = hou.node('/out/any_rop')
root.recursiveGlob(rop.evalParm('forceobject'), hou.nodeTypeFilter.Obj)
@taikomatsu
taikomatsu / create_delayed_render_objects.py
Last active January 10, 2017 14:14
Create dummy render objects and delayed load shaders with links.
# render用のdelayed loadオブジェクトとシェーダを作成する
# 当然それらにはリンクが設定してある状態になる
# SOPで任意のノード(rop_alembic, rop_geometry, filecache)を選んでshelfボタンをポチで完了
import hou
type_pairs = {'rop_alembic': 'filename',
'rop_geometry': 'sopoutput',
'filecache': 'file'}