|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Source and Procedures problem
|
|
|
This is quite odd because a script I made works when I execute its contents directly from the script editor and call its main procedure but if I source it and then execute the main procedure, it gives an error that it cannot find procedures even though they clearly exist in the file. Is there a way to solve this problem apart from making every procedure global?
|
|
|
|
hey,
if your going to call the proc from out side the script, then it needs to be global.
that or you need to have the execution command down the very bottom of the script, outside of any of the procs {}.
but only the one you want to call, so you could have :
proc printStuff() {
print "im printing a msg";
}
global proc mainCmd()
{
printStuff(); }
hope that helps
Kym
|
|
|
|
No, it does not fix the problem. It gets as far as running the first procedure but if I call a procedure from within the result of the procedure, it pops up the error. The first procedure is actually a GUI creating procedure but when I use a button it gives the error. If you really want to see the script, download “LND Outdoor Simulator 0.72” from the scripts section. Follow the instructions and then you’ll end with a new button. Look into its commands in the shelf editor and you’ll see the script (It is completely written inside the commmand section and does not refer to an outside script.)
Thanks for your reply though.
|
|
|
|
Hmm Ok,
Can you turn on in the script editor:
history>line number in errors
history>show stack trace
*Any body doing any mel scripting in maya, should have these options turned on, it makes debuging your own code so much faster.
Run the commands again so they error out.
Copy the error that you get in the stack trace window and in the script editor here.
Then open up the .mel file your calling (it will tell you in the stack trace which file it is haveing troubles with) and coy and paste the 10 or so lines around the error line numbers here.
So at least i have something i can check against, when i debug whats going on.
Cheers
Kym
|
|
|
|
Also i cant run the script correctly as i do not have access to maya2009.
What could also work, is copy the code that works.
then explain what your trying to do and ill see what i can do.
Cheers
Kym
|
|
|
|
Actually this is the only version of the code using the source command. The rest were all transferred directly into the shelf.
The error comes up as soon as I click a button.
This is the error in the MEL Stack Trace window in case of the “Create” button.
Cannot find procedure "runCommandLND". Start of trace: (command window: line 1). runCommandLND (command window: line 1).
This is the error in the script editor
// Error: line 1: Cannot find procedure "runCommandLND". //
This is the piece of code concerned
//THE UI
proc runCommandLND ()
{
//ND TimeToDegree Converter, 1 degree = 4 minutes, 12h day, 6AM to 6PM
$hourLNDbase = `intField -q -value "inputHourLND"`;
$minuteLND = `intField -q -value "inputMinuteLND"`;
//This offsets the time by -6 hours so that 0 degree is 6AM and 180 degree is 6PM
$hourLND = $hourLNDbase - 6;
int $minuteReqLNDHourVar = $hourLND * 60;
float $minuteReqLND = $minuteReqLNDHourVar + $minuteLND;
float $dirLtRotValue = $minuteReqLND / 4; //This is the value used below
//The main procedure
int $envLtScaleValue = `intSliderGrp -q -value "envLtScale"`;
string $envchoiceMenuValue = `optionMenu -q -value "envChoiceMenuMain"`;
createEnvLightNew $dirLtRotValue $envLtScaleValue $envchoiceMenuValue ;
print ($envchoiceMenuValue + " environment created with environment size " + $envLtScaleValue + " and time " + $hourLNDbase + ":" + $minuteLND + ".\n" );
}
//The close buttons's procedure proc closeWindowLND ()
{
toggleWindowVisibility envLightWindowLND;
}
proc createGuiLnd ()
{
//Creates the GUI
window -t "Create Outdoor Lighting" -w 400 -h 150 -rtf true -ret envLightWindowLND;
columnLayout optionsColumnLayout;
frameLayout -label "Environment Light Scale" -labelAlign center -borderStyle etchedIn;
columnLayout;
text -label "This slider controls the volume light's size" -align "left";
intSliderGrp -label "Environment Light Scale" -field true -minValue 10 -maxValue 1000 -fmn 10 -v 10 envLtScale;
setParent ..; setParent ..;
frameLayout -label "Time" -labelAlign center -borderStyle etchedIn;
columnLayout;
text -label "Enter the hour and minute according to the 24hr clock." -align "left";
intField -min 00 -max 24 inputHourLND;
intField -min 00 -max 59 inputMinuteLND;
setParent ..; setParent ..;
frameLayout -label "Environment" -labelAlign center -borderStyle etchedIn;
columnLayout;
text -label "Select your environment from this menu" -align "left";
optionMenu -label "Environment" envChoiceMenuMain;
menuItem -label "Plains";
menuItem -label "Snow";
menuItem -label "Desert";
setParent ..; setParent ..;
rowLayout -numberOfColumns 2;
button -c "runCommandLND" -l "Create Lighting";
button -c "closeWindowLND" -l "Close";
showWindow envLightWindowLND;
}
//The starting procedure//////////////////////////////
//Check for existing window
global proc envLtProcLND ()
{
if (`window -exists envLightWindowLND`)
{
showWindow envLightWindowLND;
} else
{
createGuiLnd;
}
}
The name of the script is envLtProcLND which is also the only global procedure here and following your previous advice all other procedures were written in the descending order of calling.
Thanks
|
|
|
|
Okay, so i can get this to work if i remove the commands that are just in maya 2009.
2 way to make this code work.
If its a button on the shelf, and all the code is in side the button.
then at the very bottom you need to have:
envLtProcLND();
So when you read the script it actually executes something.
a proc will not run unless its called.
secondly,
if you were to save the code as a .mel file, and have youre button code source it like:
source "c:/temp/envLtProcLND.mel"; envLtProcLND();
The second way works the best of you are continually changing your code or you want to easily give it to others.
Hope this helps.
Kym
|
|
|
|
No, no, you did not understand the problem. The code works if (a) It is in the button, which is why I released it with a button creating script in the area downloads; and (b) when the code is executed directly in the script editor. If I save it as an MEL file and then source and execute it, it pops up the errors. That happens on Maya 2009. I haven’t tested it on Maya 8.5. So basically the second method, which I want, does not work.
|
|
|
|
hmm.
the only way i can think that it wouldnt find the command then is if your not sourceing the script be fore you run the proc.
The other thing you can try is to make all the proc global, but if that still fails, then it means your not sourceing the script in.
Can any one else give this a go with 2009 please, and post your results.
Cheers
Kym
|
|
|
|
I have had the same problem. The trick is if you need a proc from a UI element it needs to be a global proc. Is there any reason you don’t want to use global proc’s?
You don’t have to source your script if the mel script is in a mel directory that is in the maya path. And the main global proc and the mel script are named the same thing.
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|
|
|