Skip to content

Commit

Permalink
Added Snippet houdini files
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorikawa committed Jun 11, 2020
1 parent 280824e commit a79d77d
Show file tree
Hide file tree
Showing 19 changed files with 2,405 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file added Snippet-0002 Soft Jellies/SoftJellies.hipnc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2,209 changes: 2,209 additions & 0 deletions Snippet-0007 Saving Node as Python Code/node_reconstruction.py

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
196 changes: 196 additions & 0 deletions Snippet-0010 SQLite Access/jh.shelf
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?xml version="1.0" encoding="UTF-8"?>
<shelfDocument>
<!-- This file contains definitions of shelves, toolbars, and tools.
It should not be hand-edited when it is being used by the application.
Note, that two definitions of the same element are not allowed in
a single file. -->

<tool name="SaveStateToDB" label="Save State To DB" icon="PLASMA_App">
<script scriptType="python"><![CDATA[import sqlite3 # sqlite3モジュールのインポート
import hou # Houdiniのモジュールのインポート
import datetime
from PySide2 import QtCore
from PySide2 import QtWidgets
node = hou.node("/")
# database.dbという名前のSQLiteのデータベースファイルが
# HIPファイルと同じ階層に来るようにファイルパスを作る
dbname = hou.houdiniPath()[0] + "/database.db"
### ダイアログのクラスを作る
class SaveState(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
vbox = QtWidgets.QVBoxLayout() # 縦に並べるレイアウト方式を使う
self.setGeometry(500, 300, 300, 100) # ウィンドウのサイズの指定
self.setWindowTitle('Save State') # ウィンドウのタイトルの指定
self.label = QtWidgets.QLabel('Comment', self)
vbox.addWidget(self.label, 1)
textedit = QtWidgets.QTextEdit() # テキストフィールドを作る
vbox.addWidget(textedit) # レイアウトにテキストフィールドを追加する
self.msgtextedit = textedit # ダイアログクラスのmsgtextedit変数にテキストフィールドを格納する
button = QtWidgets.QPushButton('Save State', self) # 保存ボタンを作成する
button.setFocusPolicy(QtCore.Qt.NoFocus)
vbox.addWidget(button) # ボタンをレイアウトに追加する
self.connect(button, QtCore.SIGNAL('clicked()'), self.save) # ボタンクリック時のイベントの処理を指定する
self.setLayout(vbox)
def save(self):
# sqlite3を使ってデータベースを作り、historyというテーブルを
# まだデータベースにない場合に限り新規で作成する
conn = sqlite3.connect(dbname)
c = conn.cursor()
sql_create_table = ''' CREATE TABLE IF NOT EXISTS history (
id integer PRIMARY KEY,
name text,
state_data text,
created text
); '''
c.execute(sql_create_table)
### 名前を作る
name = self.msgtextedit.toPlainText()
### ノードネットワーク再構成用のPythonコードを取得する
node = hou.node("/") # 一番上の階層のノードネットワークのパス
code = node.asCode(False, True, False, True, True, True) # ノードネットワークを再構成するためのPythonコードを取得する
### 現在の日時を取得する
created = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
sql_insert = ''' INSERT INTO history (name, state_data, created)
VALUES (
?,
?,
?
); ''' #データ挿入のクエリ文を作る
c.execute(sql_insert, [name, code, created]) # データベースにクエリを送る
conn.commit() # データベースの変更分を保存する
conn.close() # データベースの接続を切る
self.close()
dialog = SaveState()
dialog.show()]]></script>
</tool>

<tool name="LoadSaveState" label="Load Save State" icon="PLASMA_App">
<script scriptType="python"><![CDATA[import sqlite3
import hou
from PySide2 import QtCore
from PySide2 import QtWidgets
from functools import partial
node = hou.node("/")
dbname = hou.houdiniPath()[0] + "/database.db"
conn = sqlite3.connect(dbname)
c = conn.cursor()
sql_create_table = ''' CREATE TABLE IF NOT EXISTS history (
id integer PRIMARY KEY,
name text,
state_data text,
created text
); '''
c.execute(sql_create_table)
conn.commit()
sql_get_rows = ''' SELECT id, name, state_data, created FROM history ORDER BY created '''
c.execute(sql_get_rows)
rows = c.fetchall()
conn.close()
# 読み取りのダイアログのクラス
class LoadState(QtWidgets.QWidget):
def __init__(self, datas, parent=None):
QtWidgets.QWidget.__init__(self, parent)
vbox = QtWidgets.QVBoxLayout()
self.setGeometry(500, 300, 600, 300)
self.setWindowTitle('Load State')
tableWidget = QtWidgets.QTableWidget()
tableWidget.setRowCount(len(datas)) # データベースにあるデータの数だけ行を作る
tableWidget.setColumnCount(5) # 列を五つ作る
tableWidget.setHorizontalHeaderLabels(["id", "commnet", "created", "", ""])
for i in range(len(datas)):
### データベースの格納されたPythonコード以外をテーブルのセルに挿入する
tableWidget.setItem(i, 0, QtWidgets.QTableWidgetItem(str(datas[i][0])))
tableWidget.setItem(i, 1, QtWidgets.QTableWidgetItem(str(datas[i][1])))
tableWidget.setItem(i, 2, QtWidgets.QTableWidgetItem(str(datas[i][3])))
buttonLoad = QtWidgets.QPushButton("Load State") # 読み取り用のボタンを作る
buttonLoad.setFocusPolicy(QtCore.Qt.NoFocus)
buttonLoad.clicked.connect(partial(self.loadData, datas[i][2])) # ボタンクリック時の関数にデータベースに格納されたPythonのコードをパスする
tableWidget.setCellWidget(i, 3, buttonLoad) # 読み取り用のボタンを4つめの列に挿入する
buttonDelete = QtWidgets.QPushButton("Delete"); # データ削除用のボタンを作る
buttonDelete.setFocusPolicy(QtCore.Qt.NoFocus)
buttonDelete.clicked.connect(partial(self.deleteData, datas[i][0])) # 削除ボタンクリック時の関数にデータのidをパスする
tableWidget.setCellWidget(i, 4, buttonDelete) # 五つめの列に削除ボタンを挿入する
self.table = tableWidget # ダイアログのクラスの変数tableにテーブルのウィジェットを格納する
### テーブルのヘッダーのサイズを自動調整する
header = tableWidget.horizontalHeader()
header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
header.setSectionResizeMode(4, QtWidgets.QHeaderView.ResizeToContents)
vbox.addWidget(tableWidget) # テーブルのウィジェットをレイアウトに追加する
self.setLayout(vbox)
### データ読み取りのボタンを押した際に呼ばれる関数
def loadData(self, data):
exec(data) # データベースに格納されているPythonコードを実行して、ノードネットワークを再構成する
self.close()
### データ削除ボタンを押した際に呼ばれる関数
def deleteData(self, id):
### idにマッチするデータを探す
results = self.table.model().match(
self.table.model().index(0, 0),
QtCore.Qt.DisplayRole,
id,
-1,
QtCore.Qt.MatchContains
)
### foundRowに削除する対象の行番号を格納する
foundRow = -1
for result in results:
foundRow = result.row()
self.table.removeRow(foundRow) # 指定の行番号のテーブルの行を削除する
conn = sqlite3.connect(dbname)
c = conn.cursor()
sql_remove_item = ''' DELETE FROM history WHERE id = ?; ''' # 指定のidのデータをデータベースから削除するクエリを作る
c.execute(sql_remove_item, [id]) # データベースからデータを削除する
conn.commit() # データベースを更新する
conn.close()
dialog = LoadState(rows)
dialog.show()]]></script>
</tool>
</shelfDocument>
Binary file not shown.
Binary file added Snippet-0011 Circle Packing/Circle Packing.hiplc
Binary file not shown.
Binary file added Snippet-0011 Circle Packing/cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.

0 comments on commit a79d77d

Please sign in to comment.