Message 1 of 7
Hypershade shading network not always rendering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello! I created a python script that takes a substance file and opens a hypershade window, creates a substance node and loads the given substance file and then creates a shading network.
It works about 50% of the time. The rest of the time, it seems to "work" but nothing is rendered in the hypershade window and from the output logs of the command, nothing seems to be different between when it works and when it doesn't.
Here is my function that does all this. I think its pretty basic
#Function to handle submenu item clicks.
def loadSubstanceFile(self, parentMenu, subMenuItem):
geometry = cmds.ls(geometry=True)
substanceFile = importer.getMaterialLibrariesPath() + '\\' + parentMenu + '\\materials\\' + subMenuItem + '.sbsar'
if not os.path.exists(substanceFile):
filename = os.path.basename(substanceFile)
error_message = "Substance file does not exist: {}".format(filename)
QtWidgets.QMessageBox.warning(self, "Error", error_message)
return
# Check if Hypershade window exists
hypershade_exists = cmds.window('hyperShadePanel1Window', exists=True)
# Open the Hypershade window if it doesn't exist
if not hypershade_exists:
cmds.HypershadeWindow()
# Create a Substance node
substance_node = cmds.shadingNode('substanceNode', asTexture=True)
cmds.substanceNodeLoadSubstance(substance_node, substanceFile)
# Create a place2dTexture node
place2d_texture = cmds.shadingNode('place2dTexture', asUtility=True)
# Connect the place2dTexture node to the Substance node
cmds.connectAttr(place2d_texture + '.outUV', substance_node + '.uv')
cmds.connectAttr(place2d_texture + '.outUvFilterSize', substance_node + '.uvFilterSize')
# Apply the workflow
cmds.substanceNodeApplyWorkflow(substance_node, workflow=cmds.substanceGetWorkflow())
Would anyone be able to give me pointers as to where I would could look to solve this. For reference, I'm using maya 2022 and I cannot use a different version.