Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Hypershade shading network not always rendering

Hypershade shading network not always rendering

dvellucciUGA9S
Explorer Explorer
881 Views
6 Replies
Message 1 of 7

Hypershade shading network not always rendering

dvellucciUGA9S
Explorer
Explorer

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. 

0 Likes
882 Views
6 Replies
Replies (6)
Message 2 of 7

Kahylan
Advisor
Advisor

Hi!

 

From what you describe, it could be that the hypershade is already running in the background in some cases, in which case added nodes aren't dispalyed. Which is why it only works some times, as the hypershade will display the current selection when it is opened. You can try to display the incoming and outcoming nodes at the end of your code using this line:

cmds.hypershade(sn = substance_node)

this should add the entire shading network of your substance node to the graph in the hypershade.

 

I hope it helps!

 

Message 3 of 7

dvellucciUGA9S
Explorer
Explorer

Thanks for the reply. I have an error when I use this command (AttributeError: module 'maya.cmds' has no attribute 'hypershade'). Is it possible this command does not exist for maya 2022?

 

But I am able to replicate the scenario. It will work at first, but if I X out the hypershade window and run the function again, thats when the window opens but it does not render. Then if I run the command again after that it starts working. So its really when I X out the hypershade window.

0 Likes
Message 4 of 7

dvellucciUGA9S
Explorer
Explorer

Bump

0 Likes
Message 5 of 7

Kahylan
Advisor
Advisor

oh sorry, I had a typo in there, the command is hyperShade not hypershade:

cmds.hyperShade(sn = substance_node)

 

It should be supported in Maya 2016 and higher atleast accring to the documentation, I'm pretty sure you'll find the solution to your problem somewhere in this command:

https://help.autodesk.com/cloudhelp/2020/ENU/Maya-Tech-Docs/CommandsPython/hyperShade.html

 

I sadly can't quite figure out a way to test your code, as there are too many variables that I would have to manually set and files that I would have to create for it to be working on my setup.

 

 

Message 6 of 7

dvellucciUGA9S
Explorer
Explorer
No need to test. I can do that. I'll update the post with the result. Thanks again 🙂
0 Likes
Message 7 of 7

dvellucciUGA9S
Explorer
Explorer

I still have the issue unfortunately. The weird thing is the shading network appears for a split second when I open the window. I know it "exists". I just don't see it. I'm going to investigate to see if the way I'm opening the window is the reason. Thanks for your help! Any other ideas would be appreciated of course!

0 Likes