Skip to content

Commit

Permalink
houdini: improve popup menu, add export radius menu
Browse files Browse the repository at this point in the history
  • Loading branch information
atticus-lv committed May 10, 2022
1 parent 7a538ed commit ef14fec
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 8 deletions.
16 changes: 12 additions & 4 deletions third_party_addons/Super IO for Houdini/Super IO.shelf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import numpy as np
# Custom Temp Path
TEMP_DIR = ''
export_labels = [
'Wavefront (.obj)',
'Alembic (.abc)',
'OpenVDB (.vdb)',
'Stl (.stl)',
'AutoCAD DXF(.dxf)',
'Stanford (.ply)',
]
export_formats = [
'obj', 'abc', 'vdb', 'stl', 'dxf', 'ply'
]
Expand All @@ -42,14 +51,13 @@ def get_dir():
TEMP_DIR = os.path.join(os.path.expanduser('~'), 'spio_temp')
if not "spio_temp" in os.listdir(os.path.expanduser('~')):
os.makedirs(TEMP_DIR)
return TEMP_DIR
def get_export_config():
index = hou.ui.selectFromList(export_formats,
default_choices=(), exclusive=False, message=None, title=None,
column_header="Select an export format",
index = hou.ui.selectFromList(export_labels,
default_choices=(), exclusive=True, message="Select a format to export", title='Super Export',
column_header=None,
num_visible_rows=10, clear_on_cancel=False, width=200, height=300)
return index[0] if len(index) != 0 else None
Expand Down
18 changes: 14 additions & 4 deletions third_party_addons/houdini/houdini_spio_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
# Custom Temp Path
TEMP_DIR = ''

export_labels = [
'Wavefront (.obj)',
'Alembic (.abc)',
'OpenVDB (.vdb)',
'Stl (.stl)',
'AutoCAD DXF(.dxf)',
'Stanford (.ply)',
]

export_formats = [
'obj', 'abc', 'vdb', 'stl', 'dxf', 'ply'
]
Expand All @@ -30,10 +39,11 @@ def get_dir():


def get_export_config():
index = hou.ui.selectFromList(export_formats,
default_choices=(), exclusive=False, message=None, title=None,
column_header="Select an export format",
num_visible_rows=10, clear_on_cancel=False, width=200, height=300)
index = hou.ui.selectFromList(export_labels,
default_choices=(), exclusive=True, message="Select a format to export",
title='Super Export',
column_header=None,
num_visible_rows=10, clear_on_cancel=False, width=250, height=300)
return index[0] if len(index) != 0 else None


Expand Down
113 changes: 113 additions & 0 deletions third_party_addons/houdini/houdini_spio_export_radius.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os
import hou

TEMP_DIR = ''


def get_dir():
global TEMP_DIR
if TEMP_DIR == '':
TEMP_DIR = os.path.join(os.path.expanduser('~'), 'spio_temp')
if not "spio_temp" in os.listdir(os.path.expanduser('~')):
os.makedirs(TEMP_DIR)

return TEMP_DIR


def save_file(ext):
file_list = list()

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

clipboard = PowerShellClipboard()
clipboard.push_to_clipboard(paths=file_list)


import subprocess


class PowerShellClipboard():
def __init__(self, file_urls=None):
pass

def get_args(self, script):
powershell_args = [
os.path.join(
os.getenv("SystemRoot"),
"System32",
"WindowsPowerShell",
"v1.0",
"powershell.exe",
),
"-NoProfile",
"-NoLogo",
"-NonInteractive",
"-WindowStyle",
"Hidden",
]
script = (
"$OutputEncoding = "
"[System.Console]::OutputEncoding = "
"[System.Console]::InputEncoding = "
"[System.Text.Encoding]::UTF8; "
+ "$PSDefaultParameterValues['*:Encoding'] = 'utf8'; "
+ script
)
args = powershell_args + ["& { " + script + " }"]
return args

def push(self, script):
parms = {
'args': self.get_args(script),
'encoding': 'utf-8',
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
}

subprocess.Popen(**parms)

def push_to_clipboard(self, paths):
join_s = ""

for path in paths:
join_s += f", '{path}'"

script = (
f"$filelist = {join_s};"
"$col = New-Object Collections.Specialized.StringCollection; "
"foreach($file in $filelist){$col.add($file)}; "
"Add-Type -Assembly System.Windows.Forms; "
"[System.Windows.Forms.Clipboard]::SetFileDropList($col); "
)

self.push(script)


menu = {
"n": {
"type": "script_action",
"label": "Export ABC",
"script": lambda ext='vdb', **kwargs: save_file(ext),
},
"s": {
"type": "script_action",
"label": "Export OBJ",
"script": lambda ext='obj', **kwargs: save_file(ext),
},
"e": {
"type": "script_action",
"label": "Export STL",
"script": lambda ext='stl', **kwargs: save_file(ext)
},
"w": {
"type": "script_action",
"label": "Export VDB",
"script": lambda ext='vdb', **kwargs: save_file(ext),
}
}

radialmenu.setRadialMenu(menu)

0 comments on commit ef14fec

Please sign in to comment.