Author Topic: Cannot find procedure "SubstanceOutputHandleActivate"  (Read 261 times)

Hello! I am creating a simple tech-check script to verify if substance materials in a Maya scene have glossiness maps. If no glossiness map is found in my substanceNode's cacheExtension, I attempt to activate the Output to generate the map. However, I am encountering this error whenever I call the "SubstanceOutputHandleActivate" function on a fresh Maya scene (testing on a polySphere with a substance material):

Code: [Select]
mel.eval('SubstanceOutputHandleActivate substanceNode1 Glossiness 1;')
// Error: line 1: Cannot find procedure "SubstanceOutputHandleActivate". //
# Error: RuntimeError: file <maya console> line 43: Error occurred during execution of MEL script
line 1: line 1: Cannot find procedure "SubstanceOutputHandleActivate". #

If I have the HyperShade open, or re-run this part of the code twice in two different sessions, I am able to call the SubstanceOutputHandleActivate function normally. Is there some procedure I need to be calling first for Maya to recognize this function? Thanks!

The SubstanceOutputHandleActivate function is part of our Attribute editor code and is mapped to the activate output button, so it isn't meant to be a publicly exposed function. It only gets loaded when the attribute editor is opened and the substanceOutputUI.mel file is included by AEsubstanceNodeTemplate.mel.

What you will want to do instead is use the public scripting API functions and build your own function to do this. All the functions used here are defined by substancemaya.mll (the native plugin) and are available to be used. All of the buttons, etc. on the attribute editor directly build upon the primitive functions. You can see the list in the plugin manager view for the substance plugin.

You can do something like this:

substance_node = 'substanceNode1'

# Determine the number of outputs that the sbsar has
output_count = maya.cmds.substanceNodeGetOutputCount(substance_node)

# Attempt to locate the glossiness output. Note that if you just want to verify if it
# exists without actually activating them, this would be sufficient.
index = -1
for i in range(0, output_count):
    if maya.cmds.substanceNodeGetOutputUsage(substance_node, i) == 'glossiness':
        index = i
        break

# If there is a glossiness output, activate it. A negative index means that
# no glossiness output was found
if index >= 0:
    # Acquire the connected output node
    output_node = maya.cmds.substanceNodeGetOutputNodeName(substance_node, index)

    # If no output node is connected to the substance node, activate it. Last parameter
    # tells it to force render
    if not output_node:
        maya.cmds.substanceNodeActivateOutput(substance_node, index, 1)
Last Edit: June 12, 2020, 08:37:55 am
Software Engineer, Integrations
Maya, 3ds Max and Core Libraries