Transparent Battery

キリシマがてきとーする場所

ログとか

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging
import sys
def main(test=None):
    logger = logging.getLogger(__name__)
    handler = logging.StreamHandler()
    fh = logging.FileHandler('test.log', 'a+')
    handler.setLevel(logging.INFO)
    logger.setLevel(logging.INFO)
    fh.setLevel(logging.INFO)
    logger.addHandler(handler)
    logger.addHandler(fh)

    get_current_frame()
    success_logger(__file__)

def success_logger(txt):
    logger = logging.getLogger(__name__)
    logger.info(txt)

def error_logger(error_class, txt):
    logger = logging.getLogger(__name__)
    logger.error("{0}:{1}".format(error_class.__name__, txt))
    raise error_class("{0}".format(txt))


def get_current_frame():
    func_obj = sys._getframe().f_back
    print('filename: {0}'.format(func_obj.f_code.co_filename))
    print('function: {0}()'.format(func_obj.f_code.co_name))
    print('current_variables:')
    for varname in func_obj.f_locals:
        print("\t\t  {0}: {1}".format(varname, func_obj.f_locals[varname]))
    print('local_variables:')
    print func_obj.f_code.co_names

main()
'''

連番用のソート

def key_zero_fill(str1):
    if not str1:
        return ""
    import re

    a = re.match(r"(?P<str>\D*)(?P<int>\d*)(?P<next>.*)", str1)

    return a.group("str")+a.group("int").zfill(12)+key_zero_fill(a.group("next"))

list = ["test112", "test10"]
print sorted(list, key=key_zero_fill)

>>>['test10', 'test112']

memo / csvCrawl

df = None
for file in os.listdir(folderPath):
    filePath = folderPath + "\\" + file
    df = pd.concat([df, pd.read_csv(filePath)], ignore_index=True)

memo / cmds.CommandPort()

pythonコードをコマンドポートから動かす
cmds.commandPort(name=":hogehoge",sourceType="python")

でも返り値はNoneで固定なんであんまり良くない

memo / mayaの内部変数を表示

import maya.cmds as cmds
import maya.mel as mel

env = mel.eval("env;")

for x in mel.eval("env;"):
    mel.eval('print "%s\t";' %x)
    mel.eval('print %s;' %x)
    print ""

memo / HyperGraphについて

HyperGraph関連は Maya20XX > scripts > othersで呼び出されてる MarkingMenuもここらへんで書かれてる?

memo / iniCreate

# -*- coding: utf-8 -*-
def getPath(needItem):
    import os
    
    corePath = os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH")
    returnPath = []
    
    if "Desktop" in needItem:
        returnPath.append(corePath + "\\Desktop")
    if "Documents" in needItem:
        returnPath.append(os.getenv("HOME"))
    if "Pictures" in needItem:
        returnPath.append(corePath + "\\Pictures")
    if "Videos" in needItem:
        returnPath.append(corePath + "\\Videos")
    if "Music" in needItem:
        returnPath.append(corePath + "\\Music")
        
    elif len(returnPath) == 1:
        return returnPath[0]
    elif returnPath:
        return returnPath
    else:
        return None

def iniWrite(path, writeData, keys):
    import os
    if os.path.exists(path) == False: os.mkdir(path)
    if os.path.exists(path):
        with open(path + "\\setting.ini","w+") as f:
            for i in keys:
                f.writelines(i)
                f.writelines(" = ")
                f.writelines(writeData[i])
                f.writelines("\n")
                
def iniRead(path):
    import os
    result = {}
    if os.path.exists(path):
        with open(path + "\\setting.ini","r") as f:
            lines = f.readlines()
            for line in lines:
                key = line[:-1].split(" = ")[0]
                value = line[:-1].split(" = ")[1]
                result[key] = value
    return result
    
keys = ["one","two","three","four","five","six","seven","eight"]
writeData = {x : "test" for x in keys}

if __name__ == "__main__":
    path = getPath("Documents")+ "\\Record"
    iniWrite(path, writeData, keys)
    print iniRead(path)