C4DScriptいくつか
こんにちは.C4Dのスクリプトは毎回データ構造のリファレンスがどこにあるのかググっても見つからないのでリバースしてます.
リファレンスが増えるかもとの目的で作ったものを置いておきます
1.Blender→C4D想定 この前のマテリアル割り当てのFaceSetから割り当てるバージョン
import c4d from c4d import storage def main(): if not op:return path = storage.LoadDialog(title = 'File') if not path:return path = unicode(path, 'UTF-8') data_file = open(path, 'r') data = data_file.read() data_file.close() data = data.split('\n') for c in range(len(data)/3): Mat = doc.SearchMaterial(unicode(data[3*c+1], 'shift-jis')) tag = c4d.BaseTag(c4d.Ttexture) tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW tag[c4d.TEXTURETAG_MATERIAL] = Mat name = unicode(data[3*c+2], 'shift-jis') t = op.GetFirstTag() selection = None cname = name.encode('utf-8') tnameList = [] tnameFindexList = [] while t: tname = t.GetName() findIndex = tname.rfind(cname) if findIndex!=-1: tnameList.append(t) tnameFindexList.append(findIndex) t = t.GetNext() if len(tnameFindexList)>0: if len(tnameFindexList)>1: targetindex = tnameFindexList.index(min(tnameFindexList)) selection = tnameFindexList[targetindex] else: selection = tnameFindexList[0] tag[c4d.TEXTURETAG_RESTRICTION] = selection.GetName() op.InsertTag(tag, t) if __name__=='__main__': main()
2.C4D→Houdini想定 FaceSet用にポリゴン選択範囲をリネームする
import c4d from c4d import storage def main(): if not op:return path = storage.LoadDialog(title = 'File') if not path:return path = unicode(path, 'UTF-8') data_file = open(path, 'r') data = data_file.read() data_file.close() data = data.split('\n') for c in range(len(data)/3): print c name = unicode(data[3*c], 'shift-jis') newname = unicode(data[3*c+1], 'shift-jis') t = op.GetFirstTag() selection = None cname = name.encode('utf-8') tList=[] tnameFindexList=[] print cname while t: tname = t.GetName() findIndex = tname.rfind(cname) if findIndex!=-1: tList.append(t) tnameFindexList.append(findIndex) t = t.GetNext() if len(tList)>0: if len(tList)>1: targetindex = tnameFindexList.index(min(tnameFindexList)) selection = tList[targetindex] else: selection = tList[0] selection.SetName(newname) if __name__=='__main__': main()
3.C4D→Houdini_RedShift想定 マテリアル情報をCsv形式で出す
import c4d from c4d import storage import csv def main(): path = storage.SaveDialog(title = 'File') if not path:return path = unicode(path, 'UTF-8') f = open(path + '.csv', 'ab') csvWriter = csv.writer(f) val = 0 rowList = [] mats = doc.GetActiveMaterials() for a in xrange(len(mats)): rowList.append([]) matname = mats[a].GetName() df_tex = mats[a][c4d.MATERIAL_COLOR_SHADER] df_tex_path = df_tex[c4d.BITMAPSHADER_FILENAME] if df_tex else "none" spc_tex = mats[a][c4d.MATERIAL_SPECULAR_SHADER] spc_tex_path = spc_tex[c4d.BITMAPSHADER_FILENAME] if spc_tex else "none" bmp_tex = mats[a][c4d.MATERIAL_BUMP_SHADER] bmp_tex_path = bmp_tex[c4d.BITMAPSHADER_FILENAME] if bmp_tex else "none" nrm_tex = mats[a][c4d.OCT_MATERIAL_NORMAL_LINK] nrm_tex_path = nrm_tex[c4d.IMAGETEXTURE_FILE] if nrm_tex else "none" dsp_tex = mats[a][c4d.MATERIAL_DISPLACEMENT_SHADER] dsp_tex_path = dsp_tex[c4d.BITMAPSHADER_FILENAME] if dsp_tex else "none" opc_tex = mats[a][c4d.MATERIAL_ALPHA_SHADER] opc_tex_path = opc_tex[c4d.BITMAPSHADER_FILENAME] if opc_tex else "none" ObjLink = mats[a][c4d.ID_MATERIALASSIGNMENTS] myCount = ObjLink.GetObjectCount() for b in xrange(myCount): tag = ObjLink.ObjectFromIndex(doc,b) #Gets the tag that's on the object obj = tag.GetObject().GetName() sel = tag[c4d.TEXTURETAG_RESTRICTION] rowList[a] = [matname,obj,sel,df_tex_path,spc_tex_path,bmp_tex_path,nrm_tex_path,dsp_tex_path,opc_tex_path] csvWriter.writerows(rowList) f.close() # Execute main() if __name__=='__main__': main()
最近はHoudiniメインなので、次の動画が出せたら何か役立ちそうな構成とか紹介しようと思います
後は虎の子の2dレイヤー後合成スクリプト(AE)も...