Skip to content

Commit

Permalink
Merge pull request #24 from atticus-lv/feat-hou_improve
Browse files Browse the repository at this point in the history
Feat hou improve
  • Loading branch information
atticus-lv authored Jun 8, 2022
2 parents 2608ff5 + bf42bac commit cb88db4
Show file tree
Hide file tree
Showing 21 changed files with 518 additions and 65 deletions.
116 changes: 70 additions & 46 deletions ops/op_get_plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import bpy
import os
import shutil

from bpy.props import EnumProperty
from ..ui.icon_utils import RSN_Preview


class SPIO_OT_copy_c4d_plugin(bpy.types.Operator):
bl_idname = 'spio.copy_c4d_plugin'
bl_label = 'Get Cinema 4d Plugin'
bl_label = 'Install Cinema 4d Plugin'

def execute(self, context):
return {'FINISHED'}
Expand All @@ -22,54 +24,58 @@ def draw(self, context):
layout.label(text="Copy the plugin folder under c4d's /plugins/")
layout.label(text='You can find it in extension menu')

row = layout.row()

row.operator('wm.path_open', text='Install Tutorial', icon='QUESTION').filepath = os.path.join(
os.path.dirname(__file__),
'..', 'third_party_addons',
'tutorial')

file = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", 'third_party_addons', 'Super IO for Cinema 4d'))
os.path.join(os.path.dirname(__file__), "..", 'third_party_addons', 'Super IO for Cinema 4d v0.2'))
full_path = os.path.abspath(file)

row.operator('wm.path_open', text='Open', icon='FILEBROWSER').filepath = full_path


class SPIO_OT_load_text(bpy.types.Operator):
bl_idname = 'spio.load_text'
bl_label = 'Load Text'

filepath: bpy.props.StringProperty(subtype='FILE_PATH')

def execute(self, context):
with open(self.filepath, 'r') as f:
filename = os.path.basename(self.filepath)
text = f.read()
if filename in bpy.data.texts: bpy.data.texts.remove(bpy.data.texts[filename])

t = bpy.data.texts.new(name=filename)
t.write(text)
layout.operator('wm.path_open', text='Install Tutorial', icon='QUESTION').filepath = full_path

bpy.ops.spio.pop_editor(editor_text=filename)

return {'FINISHED'}
def set_hou_package_config(package_path, version='19.0'):
d = f"""
{{
"env": [
{{
"SPIO": "{package_path}"
}},
{{
"HOUDINI_PYTHONWARNINGS": "ignore"
}}
],
"path": "$SPIO"
}}
"""

doc_path = os.path.expanduser('~\Documents')
package_config_path = os.path.join(doc_path, f'houdini{version}', 'packages')
if not os.path.exists(package_config_path):
os.makedirs(package_config_path)
fp = os.path.join(package_config_path, 'SPIO.json')

item = [
('houdini_spio_import', 'Import (Shelf Tool)', ''),
('houdini_spio_export', 'Export (Shelf Tool)', ''),
('houdini_spio_export_radius', 'Export (Radial Menu)', ''),
]
with open(fp, 'w', encoding='utf-8') as f:
f.write(d)


class SPIO_OT_copy_houdini_script(bpy.types.Operator):
"""Copy to clipboard
复制到剪切板"""
""""""
bl_idname = 'spio.copy_houdini_script'
bl_label = 'Get Houdini Script'
bl_label = 'Install Houdini Package'

version: EnumProperty(name='Version', items=[
('19.0', '19.0', ''),
('18.5', '18.5', ''),
('18.0', '18.0', ''),
])

def execute(self, context):
package_path = os.path.join(
os.path.dirname(__file__),
'..', 'third_party_addons',
'Super IO for Houdini v0.3').replace('\\', '/')

set_hou_package_config(package_path, self.version)
self.report({"INFO"}, 'Successfully Write Package json File')
return {'FINISHED'}

def invoke(self, context, event):
Expand All @@ -80,21 +86,39 @@ def draw(self, context):
layout.use_property_split = True

layout.label(text='This is a script suitable for houdini 18+(python3)')
layout.label(text='You can find the icon in the folder and assign it at the shelf tool')
layout.label(text="Click 'Install' to auto install, 'Tutorial' to check tutorial image")
layout.label(text='Then assign Shortcut for it')
layout.separator()

row = layout.row()
col = row.column()
col.scale_y = 3
col.operator('wm.path_open', text='Install Tutorial', icon='QUESTION').filepath = os.path.join(
layout.prop(self, 'version')

layout.operator_context = "EXEC_DEFAULT"
layout.operator('spio.copy_houdini_script', text='Install', icon='IMPORT').version = self.version

layout.operator('wm.path_open', text='Install Tutorial', icon='QUESTION').filepath = os.path.join(
os.path.dirname(__file__),
'..', 'third_party_addons',
'tutorial')
'Super IO for Houdini v0.3')


class SPIO_OT_load_text(bpy.types.Operator):
bl_idname = 'spio.load_text'
bl_label = 'Load Text'

filepath: bpy.props.StringProperty(subtype='FILE_PATH')

col = row.column()
for file, label, des in item:
filepath = os.path.join(os.path.dirname(__file__), '..', 'third_party_addons', 'houdini', file)
col.operator('spio.load_text', text=label, icon='FILEBROWSER').filepath = filepath
def execute(self, context):
with open(self.filepath, 'r') as f:
filename = os.path.basename(self.filepath)
text = f.read()
if filename in bpy.data.texts: bpy.data.texts.remove(bpy.data.texts[filename])

t = bpy.data.texts.new(name=filename)
t.write(text)

bpy.ops.spio.pop_editor(editor_text=filename)

return {'FINISHED'}


def register():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# log
# v1.0
# v0.1
# Only Scripts
# v2.0
# v0.2
# promote into a plugin for cinema4d
#


from __future__ import annotations

Expand Down
File renamed without changes
11 changes: 11 additions & 0 deletions third_party_addons/Super IO for Houdini v0.3/Install Tutorial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1. Open 'SPIO.json'
2. Change "put package path here" to "{Current Folder Path}"
3. Copy SPIO.json to C:\Users\{user name}\Documents\houdini19.0\packages
4. Open Houdini, click '+' on tool shelf, found SPIO and add it
5. Assign Shortcut to the shelf tool and enjoy it!

1. 打开 'SPIO.json'
2. 更改 "put package path here" 为 "{当前文件夹的路径}"
3. 复制 SPIO.json 到 C:\Users\{用户名}\Documents\houdini19.0\packages
4. 打开houdini, 点击工具架 ‘+’ 加号, 找到SPIO并且添加
5. 为工具添加快捷键设置,开始使用吧!
12 changes: 12 additions & 0 deletions third_party_addons/Super IO for Houdini v0.3/SPIO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": [
{
"SPIO": "put package path here"
},
{
"HOUDINI_PYTHONWARNINGS": "ignore"
}
],
"path": "$SPIO"

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# log
# v1.0
# v0.1
# initial win
# v2.0
# v0.2
# add export format menu
# v0.3
# add alembic animation export

from __future__ import annotations

Expand All @@ -15,21 +17,29 @@
# Custom Temp Path
TEMP_DIR = ''

# label in the popup list
export_labels = [
'Wavefront (.obj)',
'Alembic (.abc)',
'OpenVDB (.vdb)',
'Stl (.stl)',
'AutoCAD DXF(.dxf)',
'Stanford (.ply)',
# animation format
'Alembic Animation (.abc)'
]

# format to export
export_formats = [
'obj', 'abc', 'vdb', 'stl', 'dxf', 'ply'
'obj', 'abc', 'vdb', 'stl', 'dxf', 'ply',
'anim-abc'
]


def get_dir():
"""get temp dir
"""
global TEMP_DIR
if TEMP_DIR == '':
TEMP_DIR = os.path.join(os.path.expanduser('~'), 'spio_temp')
Expand All @@ -39,6 +49,9 @@ def get_dir():


def get_export_config():
"""create pop up list
"""
index = hou.ui.selectFromList(export_labels,
default_choices=(), exclusive=True, message="Select a format to export",
title='Super Export',
Expand All @@ -48,6 +61,9 @@ def get_export_config():


def main():
"""run the whole script
"""
if sys.platform != "win32":
return print("Not Support this platform!")

Expand All @@ -60,21 +76,51 @@ def main():
res = get_export_config()
if res is None: return

# get ext
ext = export_formats[res]

for node in hou.selectedNodes():
# get name
name = node.path().split('/')[-1]
filepath = os.path.join(get_dir(), name + '.' + ext)
node.geometry().saveToFile(filepath)
file_list.append(filepath)

# current frame
if not ext.startswith('anim'):
filepath = os.path.join(get_dir(), name + '.' + ext)
node.geometry().saveToFile(filepath)
file_list.append(filepath)

# animation file
elif ext == 'anim-abc':
filepath = os.path.join(get_dir(), name + '.' + 'abc')

# create_node
paneTabObj = hou.ui.paneTabUnderCursor()
parent = paneTabObj.pwd()
r_node = parent.createNode('rop_alembic')

# set position, not need, will destroy node later
# net_editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
# cursor_pos = net_editor.cursorPosition()
# pos = np.subtract(cursor_pos, [-0.5, -1])
# r_node.setPosition(pos)

# connect, set parm
r_node.setInput(0, node)
r_node.parm('filename').set(filepath)
r_node.parm('trange').set(1)
# render
r_node.render(output_progress=True) # log window

# destroy
r_node.destroy()
file_list.append(filepath)

# push to clipboard
clipboard = PowerShellClipboard()
clipboard.push_to_clipboard(paths=file_list)


def set_node_path(node, path):
node.parm('file').set(path)

#### Clipboard ####

import subprocess

Expand Down Expand Up @@ -136,4 +182,5 @@ def push_to_clipboard(self, paths):
self.push(script)


# run
main()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# log
# v1.0
# v0.1
# initial win
# v2.0
# v0.2
# add more ext support, add abc/usd node support

from __future__ import annotations
Expand Down
Loading

0 comments on commit cb88db4

Please sign in to comment.