-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset.py
66 lines (51 loc) · 1.75 KB
/
asset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import maya.cmds as cmds
from mayaUtil.common import viewport
from pipelineUtil.fileSystem import winFile
# root where the tool tries to find all the assets and screenshots
# either hard code the full path or use env variable to set it
ROOT_PATH = ''
if not ROOT_PATH:
ROOT_PATH = os.path.dirname(__file__)
ASSET_PATH = os.path.join(ROOT_PATH, 'asset-library')
class Asset(winFile.WinFile):
def __init__(self, path=ASSET_PATH):
super(Asset, self).__init__(path)
self._metadir = os.path.join(self.directory, 'thumbnail')
self._thumbnail = os.path.join(self._metadir, self.base+'.jpg')
@classmethod
def fsave(cls, path):
cmds.file(rename=path)
if not cmds.ls(selection=1):
cmds.file(save=1, type='mayaAscii', force=1)
else:
cmds.file(exportSelected=1, type='mayaAscii', force=1)
asset = cls(path+'.ma')
viewport.take_screenshot(asset._metadir, asset.base)
return asset
@classmethod
def get_from_dir(cls, directory):
assets = list()
files = os.listdir(directory)
for name in files:
f = os.path.join(directory, name)
if os.path.isfile(f):
_, ext = os.path.splitext(f)
if ext in ['.ma', '.mb']:
asset = cls(f)
assets.append(asset)
return assets
@property
def thumbnail(self):
return self._thumbnail
def fopen(self):
cmds.file(new=1, force=1)
cmds.file(self.path, o=1)
def fimport(self):
cmds.file(self.path, i=1, usingNamespaces=0)
def fdelete(self):
try:
os.remove(self.path)
os.remove(self._thumbnail)
except:
pass