пятница, 20 мая 2016 г.

How can you start IPython

for install enter string:
$ pip install "ipython[all]"

in the work catalog enter:
$ iptest notebook

easy tutorial:
https://www.youtube.com/watch?v=H6dLGQw9yFQ

четверг, 19 мая 2016 г.

How can I get the current time in python

-----------------------------------------
import time
time.asctime()
>>> 'Sat May 21 01:34:38 2016'

import time
gmtime = time.gmtime(time.time())
ftime = '%a %d %b %Y %H:%M:%S GMT'
str = time.strftime(ftime, gmtime)
str
>>> 'Fri 20 May 2016 22:35:40 GMT'

----------------------------------------
import email.utils

email.utils.formatdate()
>>> 'Fri, 20 May 2016 22:37:02 -0000'

email.utils.formatdate(localtime=True)
>>> 'Sat, 21 May 2016 01:36:46 +0300'

email.utils.formatdate(usegmt=True)
>>> 'Fri, 20 May 2016 22:36:57 GMT'

---------------------------------------- 
from datetime import datetime

print datetime.now()
>>> 2016-05-21 01:38:16.661000

print datetime.now().time()
>>> 01:38:27.261000

print datetime.utcnow()
>>> 2016-05-20 22:39:04.538000

​now = datetime.now()
print '{}:{}:{}'.format(now.hour, now.minute, now.second)
>>> 1:40:12

How can I convert *.ui to *.py file

Inside PySide you can create interface with visual tool:

c:\Python27\Lib\site-packages\PySide\designer.exe

it looks like this:


after creating some interface you can converted it to python file with correct classes

c:\Python27\Scripts\pyside-uic.exe uiLogOutput.ui -o uiLogOutput.py





среда, 18 мая 2016 г.

How can I see or clear Nuke memory usage

nuke.clearRAMCache()
nuke.clearDiskCache()

def bytesto(bytes, to, bsize=1024):
    """convert bytes to megabytes, etc.
    sample code:
    print('mb= ' + str(bytesto(314575262000000, 'm')))
    sample output:
    mb= 300002347.946
    """
    a = {'k': 1, 'm': 2, 'g': 3, 't': 4, 'p': 5, 'e': 6}
    r = float(bytes)
    # print 'r {}'.format(r)
    for i in range(a[to]):
        r = r / bsize

    return (r)

print nuke.memory("info")
print nuke.memory("info", 'Read1')

print '{} Mb'.format(bytesto(nuke.memory("free"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("usage"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("total_ram"),'m'))
print '{} Gb'.format(bytesto(nuke.memory("total_vm"),'g'))

read about memory options:
print help(nuke.memory)

How do I read menu object in Nuke

inside the menu.py in Nuke, write global variable
n = nuke.menu('Nuke')

I can read the value of this object

print n.items().pop().items()[0].name()
print n.items().pop().items()[0].script()
print n.items().pop().items()[0].shortcut()

for menu_item in n.items():
    print menu_item.name()
    for menu_sub in menu_item.items():
       try:
           print '...{}'.format(menu_sub.name())
           print '...{}'.format(menu_sub.script())
           # print '...{}'.format(menu_sub.shortcut())
       except:
            pass
=========================
# Result: File
...New Comp...
...nuke.scriptNew("")
...Open Comp...
...nuke.scriptOpen("")
...Open Recent Comp
...Close Comp
...nuke.scriptClose()
...
...Save Comp
...nuke.scriptSave("")
...Save Comp As...
...nuke.scriptSaveAs("")
...Save New Comp Version
...nukescripts.script_and_write_nodes_version_up()
...
...Insert Comp Nodes...
...nukescripts.import_script()
...Export Comp Nodes...
...nukescripts.export_nodes_as_script()
...Comp Script Command...
...nukescripts.script_command('')
...Run Script...
...tcl_file()
...@;Next Frame
...frameBackward()
...@;Previous Frame
...frameForward()
...Comp Info
...nukescripts.script_data()
...
...Clear
...nuke.scriptClear()
...&Recent Files
Edit
...Undo
...nuke.undo()
...Redo
...nuke.redo()
...
...Cut
...nuke.nodeCopy(nukescripts.cut_paste_file()); nukescripts.node_delete(popupOnError=True)
...Copy
...nuke.nodeCopy(nukescripts.cut_paste_file())

and so on 

How do I write try...except in one string

1. for nuke:
exec('try:\n    n = nuke.toNode(\'DisableNodeController\'); k = n.knob(\'disable\'); k.setValue(0);\nexcept:\n   nuke.message(\'DisableNodeController is not in scene\')')

2. second variant
def safecall(f, default=None, exception=Exception):
    '''Returns modified f. When the modified f is called and throws an
    exception, the default value is returned'''
    def _safecall(*args,**argv):
        try:
            return f(*args,**argv)
        except exception:
            return default
    return _safecall

[safecall(int)(i) for i in '1 2 x'.split()]   # returns [1, 2, None]

[safecall(int, -1, ValueError)(i) for i in '1 2 x'.split()]    # returns [1, 2, -1]

суббота, 7 мая 2016 г.

How print module attributes in the readable form

# easy function print list of the module attributes
# in the readable form
def print_module_attr(module, step_in=7):
    attr_list = dir(module)
    try:
        num_line = int(ceil( len(attr_list)/step_in ))
        for i in range(num_line):
            print attr_list[i*step_in: (i+1)*step_in]
    except ValueError as e:
        print 'step_in must be not zero,\n error: {}'.format(e)
        return
    except TypeError as e:
        print 'step_in must be int type,\n error: {}'.format(e)
        return

def test_print_module_attr():
    import os
    print_module_attr(os, 8)

    temp = 'test'; print temp
    print_module_attr(temp, 8)

    temp = 1; print temp
    print_module_attr(temp, 8)

    import os; print '0.003'
    print_module_attr(os, 0.003)

    print '1, 3'
    print_module_attr(1, 3)

test_print_module_attr()

>>> ['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT', 'O_RANDOM', 'O_RDONLY']
['O_RDWR', 'O_SEQUENTIAL', 'O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH']
['P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET']
['TMP_MAX', 'UserDict', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__doc__']
['__file__', '__name__', '__package__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list']
['_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', 'abort', 'access', 'altsep', 'chdir']
['chmod', 'close', 'closerange', 'curdir', 'defpath', 'devnull', 'dup', 'dup2']
['environ', 'errno', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv']
['execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fstat', 'fsync', 'getcwd']
['getcwdu', 'getenv', 'getpid', 'isatty', 'kill', 'linesep', 'listdir', 'lseek']
['lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep']
['pipe', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'remove']
['removedirs', 'rename', 'renames', 'rmdir', 'sep', 'spawnl', 'spawnle', 'spawnv']
['spawnve', 'startfile', 'stat', 'stat_float_times', 'stat_result', 'statvfs_result', 'strerror', 'sys']
['system', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'umask', 'unlink', 'unsetenv']
['urandom', 'utime', 'waitpid', 'walk', 'write']
test
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__']
['__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__']
['__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__']
['__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split']
['_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs']
['find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace']
['istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace']
['rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines']
['startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
1
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__']
['__divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__hash__']
['__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__']
['__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__']
['__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__']
['__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__']
['__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__']
['__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
0.003
step_in must be int type,
 error: range() integer step argument expected, got float.
1, 3
['__abs__', '__add__', '__and__']
['__class__', '__cmp__', '__coerce__']
['__delattr__', '__div__', '__divmod__']
['__doc__', '__float__', '__floordiv__']
['__format__', '__getattribute__', '__getnewargs__']
['__hash__', '__hex__', '__index__']
['__init__', '__int__', '__invert__']
['__long__', '__lshift__', '__mod__']
['__mul__', '__neg__', '__new__']
['__nonzero__', '__oct__', '__or__']
['__pos__', '__pow__', '__radd__']
['__rand__', '__rdiv__', '__rdivmod__']
['__reduce__', '__reduce_ex__', '__repr__']
['__rfloordiv__', '__rlshift__', '__rmod__']
['__rmul__', '__ror__', '__rpow__']
['__rrshift__', '__rshift__', '__rsub__']
['__rtruediv__', '__rxor__', '__setattr__']
['__sizeof__', '__str__', '__sub__']
['__subclasshook__', '__truediv__', '__trunc__']
['__xor__', 'bit_length', 'conjugate']
['denominator', 'imag', 'numerator']
['real']

среда, 4 мая 2016 г.

Kick Ass GUI

Alien


Helicopter by layers


Zippo Windproof Lighter - film shot - Stritreysery (2008)





demo for masterclass at the conference "cg event 2009" Moskow



Art of Revenge

Return of Simbad TV series



Return of Simbad TV series



crazy helicopter pilot - viral advertising - 2009



SILVER BULLET (Arnold Render, Maya )


Прокофьев-Северский
2D, pencil

bat file render in command line with kick.exe

@for %%i in (%*) do C:\solidangle\mtoadeploy\2013\bin\kick.exe -nstdin -l C:/solidangle/mtoadeploy/2013/shaders %%i -g 2.2 -dw -dp -nocrashpopup
pause
- drag-and-drop files on the bat file icon and begin rendering

PIANO (Arnold Render)




Arnold-Maya Subdivision Attribute to multiple objects

import maya.cmds as cmds
zveno_lst = cmds.ls('zveno*',type='geometryShape')
for i in zveno_lst:
   cmds.setAttr( '{}.aiSubdivType'.format(i), 1 ) 

Постоянные читатели