Slava Sych

Kopatych91

About Me

Connect

LOCATION
Dnipro, Not Specified
WEBSITE

Houdini Skills

Availability

Not Specified

Recent Forum Posts

Solaris does not recognize Python-made Karma materials Aug. 30, 2024, 4:25 a.m.

CrisDoesCG
Ok so for the solution on how to create a Karma Material Builder using Python, there are two ways:

1. Doing it yourself, something like this (sorry for the messy code):
import hou

INHERIT_PARM_EXPRESSION = '''n = hou.pwd()
n_hasFlag = n.isMaterialFlagSet()
i = n.evalParm('inherit_ctrl')
r = 'none'
if i == 1 or (n_hasFlag and i == 2):
    r = 'inherit'
return r'''

destination_path = "/PATH/TO/THE/MATERIAL/DESTINATION"
destination_node = hou.node(destination_path)

subnetNode = destination_node.createNode("subnet","NAME_OF_YOUR_MATERIAL")
subnetNode.moveToGoodPosition()
subnetNode.setMaterialFlag(True)                  

parameters = subnetNode.parmTemplateGroup()

newParm_hidingFolder = hou.FolderParmTemplate("mtlxBuilder","MaterialX Builder",folder_type=hou.folderType.Collapsible)
control_parm_pt = hou.IntParmTemplate('inherit_ctrl','Inherit from Class', 
                    num_components=1, default_value=(2,), 
                    menu_items=(['0','1','2']),
                    menu_labels=(['Never','Always','Material Flag']))


newParam_tabMenu = hou.StringParmTemplate("tabmenumask", "Tab Menu Mask", 1, default_value=["MaterialX parameter constant collect null genericshader subnet subnetconnector suboutput subinput"])
class_path_pt = hou.properties.parmTemplate('vopui', 'shader_referencetype')
class_path_pt.setLabel('Class Arc')
class_path_pt.setDefaultExpressionLanguage((hou.scriptLanguage.Python,))
class_path_pt.setDefaultExpression((INHERIT_PARM_EXPRESSION,))   

ref_type_pt = hou.properties.parmTemplate('vopui', 'shader_baseprimpath')
ref_type_pt.setDefaultValue(['/__class_mtl__/`$OS`'])
ref_type_pt.setLabel('Class Prim Path')               

newParm_hidingFolder.addParmTemplate(newParam_tabMenu)
newParm_hidingFolder.addParmTemplate(control_parm_pt)  
newParm_hidingFolder.addParmTemplate(class_path_pt)    
newParm_hidingFolder.addParmTemplate(ref_type_pt)             

parameters.append(newParm_hidingFolder)
subnetNode.setParmTemplateGroup(parameters)

You will obviously need to delete the nodes that are inside the network, create the outputs and the necessary nodes. But this gives at least a base that will be recognized by Solaris when trying to import it via `sceneimport` node. Also this will give you more control in comparison to



2. Following this video [youtu.be], this works inside a LOP network, but won't work inside any other regual material network. Here is the code:
import hou
import voptoolutils

mask = voptoolutils.KARMAMTLX_TAB_MASK

viewer = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)

kwargs = {
    "pane":viewer,
    "autoplace":True
}

voptoolutils.createMaskedMtlxSubnet(kwargs,"karmamaterial",mask,"Karma Material Builder", "kma")

Thanks to u/EconomyAppeal1106 from this thread [www.reddit.com] who pointed me to their video.


Hi, you can try using the _setupMtlXBuilderSubnet function to configure the node in your specific target path in the LOP, it also works.

import hou
import voptoolutils

mask = voptoolutils.KARMAMTLX_TAB_MASK

sel = hou.selectedNodes()[0]
root = sel.parent()

materialLibrary = sel.createOutputNode("materiallibrary", "MaterialLibrary")
kmaPath = materialLibrary.createNode("subnet", "karmamaterial")
voptoolutils._setupMtlXBuilderSubnet(kmaPath, "karmamaterial", "karmamaterial", mask, "Karma Material Builder", "kma")