Skip to content

Instantly share code, notes, and snippets.

@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_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)
from maya import OpenMaya
from pymel.core import *
def mdagpath_from_name(name, extend_to_shape=False):
if not objExists(name):
raise MayaNodeError, name
slist = OpenMaya.MSelectionList()
slist.add(name)
dagpath = OpenMaya.MDagPath()
slist.getDagPath(0, dagpath)
@taikomatsu
taikomatsu / bb_submit_houdini_shelf.py
Last active September 15, 2016 15:44
Submit jobs to Backburner from Houdini shelf
# 超簡易Backburner Submitterスクリプト
# IFDを所定のフォルダに出力した後に、backburnerに投げたいROP(mantraのみ)を選んでこのツールを実行
# 各ROPのIFDの場所を読んでコマンドを生成してジョブを投げる
# 生成したコマンドやタスクファイルは、$HIP/dispatch以下に格納され、それが実行されるという流れ
# 基本的にはShelfに登録して使う想定
# priorityやserversなどはROP側に新規でparm追加して読むなどすればROP側での調整も可能だが未対応
import hou
import os
import os.path
@taikomatsu
taikomatsu / extend_curve.vfl
Created November 28, 2016 05:35
extend curve (vex)
// curveの先端を接線(というか隣のポイントとの差分)を使って伸ばす
vector p0 = point(0, "P", 0);
vector p1 = point(0, "P", 1);
vector np0 = point(0, "P", i@numpt-1);
vector np1 = point(0, "P", i@numpt-2);
vector tan_in = normalize(p0-p1);
vector tan_out = normalize(np0 - np1);
float ext = ch("ext");
addpoint(0, p0+tan_in*ext);
@taikomatsu
taikomatsu / bakecam.py
Last active January 10, 2017 14:06
Create clone cameras for data exchanging with other DCC apps.
# Houdiniにカメラを持っていく用に、値をbakeしてシンプルなデータにするための処理を自動化。
# 一応複数対応してる感じで書いてるけど、あんまり想定してないしテストもしていないw
# filmoffsetに関して、アニメーションの再接続をしているもののこれもそのままは持っていけないので一応やってるだけ。
# bakeするレンジはtime sliderに準拠する。
from pymel.core import *
cams = []
for o in selected():
new_cam = duplicate(o, rr=True)[0]
@taikomatsu
taikomatsu / gat_MDagPath_from_object_name.py
Last active January 10, 2017 14:07
Get MDagPath from object name
from maya import OpenMaya
import pymel.core as pm
def mdagpath_from_name(name):
if not pm.objExists(name):
raise MayaNodeError, name
slist = OpenMaya.MSelectionList()
slist.add(name)
dagpath = OpenMaya.MDagPath()
slist.getDagPath(0, dagpath)