Bug Report: MEL Scripting assignCreatedShader

zoe.nelsonP754P
Contributor
Contributor

Bug Report: MEL Scripting assignCreatedShader

zoe.nelsonP754P
Contributor
Contributor

I'm here to report a bug since I cannot contact support directly since I am using an educational version of Maya 2024.

 

When I run a script in the script editor, there is a bug with the assignCreatedShader command. If I open a script that has the command, even if it worked previously, upon reopening or copying in the text directly, the syntax highlighting is gone and my code throws an error at the line, as if it cannot understand the command. 

See first screenshot

 

// Error: line 31: Cannot find procedure "assignCreatedShader".

 

If I manually go in, and re-type the command, it turns the correct syntax color, but throws the same error again.

See second screenshot.

 

The only way around the bug is to manually right click > assign new material to my object and then copy in the echoed command from the history. Then my code will run as intended with no errors thrown.

 

Can someone at Autodesk please fix this?

Reply
Accepted solutions (1)
385 Views
2 Replies
Replies (2)

FirespriteNate
Advocate
Advocate
Accepted solution

This is not a bug, and not something that can (or will ever) be fixed. Maya is made up of 100s of .mel scripts, and each one of these script files can contain multiple global (and local) procedures. 

Global procedures can only be called by code once the script they live inside has been "sourced". Many scripts are sourced by Maya booting up, but there are so many, that Maya cannot realistically be expected to load ALL of these scripts at startup, as that would be a collosal waste of time and memory, so it only loads them on demand. 

 

I don't know for certain as I don't have Maya in front of me, but I'm guessing assignCreatedShader is a global proc inside another MEL script that is NOT sourced by default (maybe hypershade.mel?), as it's not necessary for general startup. When you perform a RMB-click and open a popupmenu and choose "assign new material", Maya is sourcing the mel script that contains the assignCreatedShader global function under the hood, and it's therefore available from that point on.

If you want to use Maya's built-in global procedures, it's your job as a scripter to understand where they live and and how to source them manually.

If you first ensure the function you want IS loaded/accessible, and then do:

whatIs assignCreatedShader;    // (or any other global proc name)

Maya will tell you what mel script that global function comes from (assuming it's not a real or RunTime command). You just then have to source that script before you use it, and the procedure(s) inside will always be availble to you.

So, basically, at the START of your script you just add:

source "c:/Program Files/Autodesk/Maya2022/scripts/hypershade.mel";

or whatever the actual path is that whatIs returned.

zoe.nelsonP754P
Contributor
Contributor

Thank you so much for this reply. I was starting to wonder if there was something going on under the hood that I wasn't aware of since I'm very new to MEL. Your explanation makes complete sense and why calling the command manually solves the issue by loading the procedure that my script wasn't. Thank you for taking the time to explain why it was happening. I followed your instructions to find the path and source the procedure and it worked! Thank you so much for your insight.

 

I'm curious as to your thoughts as to why it isn't being loaded until I source it when it seems to be in a startup folder. Shouldn't that mean it runs that procedure when Maya starts?

source "C:/Program Files/Autodesk/Maya2024/scripts/startup/createAndAssignShader.mel";

 

0 Likes