-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhoudini_tools.py
122 lines (94 loc) · 3.35 KB
/
houdini_tools.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- coding: utf-8 -*-
# Adam Thompson 2018
import project_launcher
import importer
import saver
import software_tools
import hou
import os
try:
# < Nuke 11
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
import PySide.QtGui as QtGuiWidgets
import PySide.QtUiTools as QtUiTools
except:
# >= Nuke 11
import PySide2.QtCore as QtCore
import PySide2.QtGui as QtGui
import PySide2.QtWidgets as QtGuiWidgets
import PySide2.QtUiTools as QtUiTools
SOFTWARE = "houdini"
class HoudiniTools(software_tools.SoftwareTools):
def __init__(self):
self.software = SOFTWARE
def debug_msg(self, msg):
print(msg)
def _save_as(self, path):
try:
hou.hipFile.save(path)
return True
except:
return False
def _save(self):
try:
hou.hipFile.save()
return True
except:
return False
def get_project_path(self):
return hou.hipFile.path()
def is_project_modified(self):
return hou.hipFile.hasUnsavedChanges()
class HoudiniProjectLauncher(project_launcher.ProjectLauncher):
def __init__(self):
self.houdini_tools = HoudiniTools()
super(HoudiniProjectLauncher, self).__init__(
QtGuiWidgets.QApplication.activeWindow(), self.houdini_tools)
def launchProject(self, filePath):
tokenDict = self.get_token_dict()
self.houdini_tools.debug_msg("Setting environment variables: ")
for token in tokenDict:
os.environ[token] = tokenDict[token]
self.houdini_tools.debug_msg(token + " = " + tokenDict[token])
self.houdini_tools.debug_msg("Here we go!")
hou.allowEnvironmentToOverwriteVariable("JOB", True)
hou.putenv("JOB", "COOL DUDE")
forwardSlashPath = filePath.replace('\\', '/')
hou.hipFile.load(forwardSlashPath)
return True
class HoudiniImporter(importer.Importer):
def __init__(self):
self.houdini_tools = HoudiniTools()
super(HoudiniImporter, self).__init__(
QtGuiWidgets.QApplication.activeWindow(), self.houdini_tools)
self.houdini_tools.debug_msg("Starting houdini importer...")
def import_file(self, file_path):
try:
basename, ext = os.path.splitext(os.path.basename(file_path))
obj = hou.node("/obj")
self.houdini_tools.debug_msg(basename)
obj_node = obj.createNode("geo", basename, run_init_scripts=False)
file_node = obj_node.createNode("file", basename)
file_node.parm("file").set(file_path)
return True
except:
raise
return False
class HoudiniSaver(saver.Saver):
def __init__(self):
self.houdini_tools = HoudiniTools()
super(HoudiniSaver, self).__init__(
QtGuiWidgets.QApplication.activeWindow(), self.houdini_tools)
self.houdini_tools.debug_msg("Starting houdini saver...")
def save_file(self, file_path):
try:
hou.hipFile.save(file_path)
return True
except:
return False
def setup():
current_dir = os.path.dirname(os.path.abspath(__file__))
houdini_path = os.path.join(current_dir, 'houdini')
current_path = hou.getenv("HOUDINI_PATH")
hou.putenv("HOUDINI_PATH", "&;" + houdini_path + ";" + current_path)