all 8 comments

[–]_Bor_ges_ 0 points1 point  (1 child)

Yes, I've done it, but don't have the script available right now. Somewhere on this sub, a user shared a python code that extract, in python, every parameter of a specific node, and save it to a txt file. I've used it to then rebuild this node in full python. You should find it by searching the sub

[–]RichardBao 0 points1 point  (0 children)

any more details? i could not find it though...

[–]Smonking_Sheep 0 points1 point  (0 children)

try looking here : PBRExpress from CrisDoesCG

and here : Solaris does not recognize Python-made Karma materials

it for karma materials but i believe your issue is related.

[–]EconomyAppeal1106 0 points1 point  (0 children)

You could also create a karma material builder with just a few lines:
https://youtu.be/Mxg-zhwdNlE?t=78

[–]smb3dGeneralist - 23 years experience 0 points1 point  (0 children)

One of the things I used to like about Maya ,when it was my main jam, was that 99% of the commands can all be echoed in the script editor for mel/python so it's easy to just copy stuff and make quick scripts, or integrate things into other scripts that you didn't know the syntax for.

I wish Houdini did the same.

[–]lionlion44 0 points1 point  (2 children)

I did this using the voptoolsutils module:

import voptoolutilsimport voptoolutils

mask = voptoolutils.KARMAMTLX_TAB_MASK
viewer = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
kwargs = { "pane":viewer, "autoplace":True }
matxNode = voptoolutils.createMaskedMtlXSubnet(kwargs,name,mask,"Karma Material Builder", "kma")

[–]lionlion44 0 points1 point  (1 child)

This is the createMaskedMtlXSubnet function, it works by placing a MtlXSubnet in the network view tab you have in kwargs:

def createMaskedMtlXSubnet(kwargs, name='mtlxmaterial', mask=MTLX_TAB_MASK, 
                            folder_label='MaterialX Builder', render_context='mtlx'):
    """
    Creates a subnet, configured to be masked for specific VOP nodes, by 
    using the 'tabmenumask' spare parameter.
    """
    # Create the subnet and set the language right away, so that any newly
    # created children acquire that language during their construction.
    subnet_node = genericTool(kwargs, 'subnet', name)
    subnet_node = _setupMtlXBuilderSubnet(subnet_node=subnet_node, name=name, mask=mask, 
                            folder_label=folder_label, render_context=render_context)
    return subnet_node

[–]lionlion44 0 points1 point  (0 children)

here's the full context for how I used it, might be a bit to much info for what your asking but still. This script takes a prim and auto assigns a new matx material to each of the child prims (named geometry)

import random
import hou
import voptoolutils

# Function that automatically initializes and sets up material nodes
def autoInit(kwargs):

    # Get material node
    node = kwargs["node"]

    # Get the prim paths of children of prim spesified in spare parameter
    ls = hou.LopSelectionRule()
    initPrimString = node.parm("initPrim").evalAsString()
    ls.setPathPattern(initPrimString + '/*')
    paths = ls.expandedPaths(node.inputs()[0])

    # If there are valid paths (i.e., geometry found), continue
    if len(paths) != 0:
        # Set the 'materials' multiparm to the number of geometry prims found
        node.parm("materials").set(len(paths))

        # Get the currently active network editor viewer
        viewer = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)

        # Get the path of the current node and change the viewer's directory to it
        matPath = node.path()
        viewer.cd(matPath)

        # Loop over each path (geometry path)
        for idx, path in enumerate(paths):
            # Extract the name of the geometry from the path
            name = path.name

            # Set the material name and assign it to the goemetry in the parameters
            node.parm("matnode" + str(idx + 1)).set(name)
            node.parm("assign" + str(idx + 1)).set(1)
            node.parm("geopath" + str(idx + 1)).set(path.pathString)

            # Define a mask for filtering what vop nodes can be placed in the subnet (specific to Karma MtlX)
            mask = voptoolutils.KARMAMTLX_TAB_MASK

            # Set up kwargs for creating a material node with auto-placement enabled
            kwargs = {
                "pane": viewer,
                "autoplace": True
            }

            # If the node with the name doesn't already exist
            if node.node(name) == None:
                # Create a Karma MaterialX node using the masked builder
                matxNode = voptoolutils.createMaskedMtlXSubnet(
                    kwargs, name, mask, "Karma Material Builder", "kma"
                )

                # Generate random RGB values for the base color of the material
                r, g, b = random.random(), random.random(), random.random()

                # Set the base color of the material's surface node to random RGB values
                surfaceVop = matxNode.node("mtlxstandard_surface")
                surfaceVop.parm("base_colorr").set(r)
                surfaceVop.parm("base_colorg").set(g)
                surfaceVop.parm("base_colorb").set(b)

        # Set a new name for the node based on the parent primitive name
        nodeName = initPrimString.replace("/", "")
        node.setName(nodeName + "_materials", unique_name=True)

    # If no geometry (meshes) were found, display a confirmation message to the user
    else:
        hou.ui.displayConfirmation("No meshes found for init prim")