My problem is I cannot write script more that 800 lines in MAYA- 7 so I am going to split my script and save it to different .mel file.
Now , How can I call my method from other .mel file?
Thanks advance.
My problem is I cannot write script more that 800 lines in MAYA- 7 so I am going to split my script and save it to different .mel file.
Now , How can I call my method from other .mel file?
Thanks advance.
QUOTE(CyberSoftHa @ 09/24/07, 11:32 AM) [snapback]273732[/snapback]
Now , How can I call my method from other .mel file?
functions! Methods are funtions that are assosicated with objects. and maya just has functions.
3 ways:
buy calling the function by name if this function is in a file with the name name.mel and its in your lookup path then maya automatically loads it. Proc must be global
source the file with the function then call it by name proc must be global
OR put it as a global proc in a other file that you also call in this case you dont need to source as it gets sourced on the other call.
PS: if you really have a over 800 lines long mel then be sure it is a substantial gui item, since if its a computational thing then youve probably missed entire point of maya big time.
QUOTE(Joojaa @ 09/24/07, 04:15 PM) [snapback]273739[/snapback]
functions! Methods are funtions that are assosicated with objects. and maya just has functions.
PS: if you really have a over 800 lines long mel then be sure it is a substantial gui item, since if its a computational thing then youve probably missed entire point of maya big time.
I cannot understand the above quote and i'll try my best to do that.
and can you explain what you mean for lookup path
Basically i am a software engineer of VB, .NET UI Desigen (I don't know Technology terms of Maya keywords)
Thank you.
QUOTE(CyberSoftHa @ 09/25/07, 08:47 AM) [snapback]273795[/snapback]
Basically i am a software engineer of VB, .NET UI Desigen (I don't know Technology terms of Maya keywords)
Thank you.
This will become your biggest burden.
Mayas computational access is split into 2. Into a scripting language and into a computation and service API. Doing mel or python does not matter its the same structure nevertheless.
The scripting language provides 2 services, journaling and gui building blocks. The idea of journaling part is to use the api tool set to build up all computation, it is a sort of recipe language. Where all the instructions are in place but all serious computation are left for the dg mechanism.
The gui section provides you with basic gui facilities and very limited events, these events are on purpose totally useless for any kind of more demanding computation. Because thats not what you should do, so to minimize abuse. Does not mean you cant abuse things, oh no many people live their entire lives doing that and they get at most 10% of mayas effect at eny given time.
The only really computational scripting facility is the expression node which although it can should not be scripted in.
So maya programming should be split too into 2 parts, its recommendable it keeps you much happier. Gui part shoul work gui time and rearrange things for right computation during dg time since you have many milliseconds to do this coplexity is not a issue. Computation should be kicked out to dg time evaluation. This way you get most out of maya. And indeed for many things its the ONLY way to go.
QUOTE
and can you explain what you mean for lookup path
works exactly the same way as dll lookup works in windows, mayas been told search/watch certain folders for scripts (maya does this once eat every stratup you can force maya to do this by calling rehash 7.0 and newere mayas only tough). Defining this works the sameway as defining system path variable.
You can kindly ask maya for the folders its currently watching:
getenv MAYA_SCRIPT_PATH
PS: never ever put anything in the factory scripts folders (ones that come with maya) for any reason whatsoever. always put it in a path thats later in the list thisway you can revert to original behavior WHRN you screw up (you will)
it is working but with some conditions
(I am not sure that is working properly(once i call a global method it'ill available upto when i close Maya application)
Thank you.
Thats what i told you.
but point 2 is not accurate, you can have as many local functions as possible (private is again a Object oriented vocabulary, theres a difference privates can be many one for each instance of the oop local is always just that one and only one! even oop has local wich is part of the scoping rules). Its got much to do with scope each file is a separate scope jsut like each {} is a separate scope so arround a file imageine a {}. Now its still just all in one jumble, once the fil is loaded all that was in it is loaded so if you define 2 global procs you can run them both, its very simple think them as variables (thats what they are):
imagine mel file test.mel with
global proc test() and
global proc test2()
then test2 got automatically loaded! when you call
test(); // youve now insured test and test2 is loaded.
....
test2(); //will work
but
test2();
test();
wont unless the proc is allready loaded elsewhere such as
source test
If you run anything in the script editor its always global unless you scope it with {} so now you can think everything as in one script.
So you can also put as many global procs in one file and source the file first.
QUOTE
the name.mel path should be in C:\Doc~\My Doc~\maya\7.0\scripts
No, it should be in ANY of your defined path variables, for example i have 28 folders for easier management but simplistically thinking yes.
PS: but this all is basic programming concepts that even apply in c# and vbscript, you should already know all this as its the fundamental basis of both those languages. Even the lookup path thinking is exactly the same. Tough fetching has different names yes, and yes you project has a path for lookup.
QUOTE
(I am not sure that is working properly(once i call a global method it'ill available upto when i close Maya application)
Yes it is permanent for the session. you can redefine it but not delete it.
QUOTE(Joojaa @ 09/25/07, 01:16 PM) [snapback]273814[/snapback]
Thats what i told you.
imagine mel file test.mel with ......................................
PS: but this all is basic programming concepts that even apply in c# and vbscript, you should already know all this as its the fundamental basis of both those languages. Even the lookup path thinking is exactly the same. Tough fetching has different names yes, and yes you project has a path for lookup.
Yes it is permanent for the session. you can redefine it but not delete it.
Yes, in c# well create an object for that file and call like
objectName.MethodName();
But in mell i am calling like
CODE
string $ctrMenu7 = menuItem -label "setProject" -c("SetProject");
menuItem -divider true;
menuItem -label "&Quit" -c ("cmdCloseWndMain(\"" + window -q -title $myWinShowCameraView + "\")");
melCreateObjectMenu;
menu -label "&Transform" -tearOff true;
here melCreateObjectMenu is my global procedure (as well as melCreateObjectMenu.mel) when i call the above code its showing error
CODE
// Error: line 43: Cannot find procedure "melCreateObjectMenu". //
Can i get a sample code?
Thanks for your patient and reply joojaa.
As is said above maya does not update what is in each folder every time you call something. it odes so once on restart, if yuou add something you must issue rehash for maya to update the lookup tree.
This is the most probable cause.
And secondly you should actually ask maya what the folders are with getenv as above as nothing guarantees your maya uses the folders you think it uses if you never bothered to ask maya.
QUOTE
objectName.MethodName();
Yes but thats because its oop. maya has just one object! Everything is in it!
oop
objectName.MethodName()
is just shorthand for writing
MethodName(objectDatablock)
in some preprocessing/compile phase.
the underlying mmethodology is exactly the same thing, if you dont the underlying idea you will end up with huge problem sooner or later. Like today.
QUOTE(Joojaa @ 09/25/07, 02:03 PM) [snapback]273818[/snapback]
As is said above maya does ..............................
Yes but thats because its oop. maya has just one object! Everything is in it!
oop
objectName.MethodName()
...................
Thats why i never tried OOp's concepts here and looking for MAYA experts reply.
QUOTE(Joojaa @ 09/25/07, 02:03 PM) [snapback]273818[/snapback]
MethodName(objectDatablock)
Can you explain MethodName(objectDatablock).
If i give objectDatablock there then how can i pass values to my perameter?
QUOTE(Joojaa @ 09/25/07, 02:03 PM) [snapback]273818[/snapback]
if you dont the underlying idea you will end up with huge problem sooner or later. Like today.
If the day comes again then; I hope there'll be some experts will point me in correct direction (Just kidding).
I think, it will be more helpfull if i get an example how to call a global proc from another file.
Thank you
I am saving my scripts in the below path
C:\Doc~ and Sett~\h~\My Doc~\maya\7.0\scripts
Below is my script
Script Global:
CODE
global proc ThisIsGlobalProc()
{
print "\n ThisIsGlobalProc \n";
ThisIsLocalProc;
}
proc ThisIsLocalProc()
{
print "\n ThisIsLocalProc\n";
}
and i am saving as ThisIsGlobalProc.mel in path "C:\Doc~ and Sett~\h~\My Doc~\maya\7.0\scripts"
then below is the script to call above globale procedure
CODE
proc CallTheGlobalProc()
{
ThisIsGlobalProc;
}
CallTheGlobalProc();
and i am saving it as MyProcedure in path "C:\Doc~ and Sett~\h~\My Doc~\maya\7.0\scripts"
now if i load the script MyProcedure.mel and executing but it is showing the error
CODE
// Error: line 4: Cannot find procedure "ThisIsGlobalProc". //
can any one point me where and what is the problem with the scripts?
Thank you
QUOTE(CyberSoftHa @ 09/25/07, 12:00 PM) [snapback]273822[/snapback]
I think, it will be more helpfull if i get an example how to call a global proc from another file.
you just call it!
procname();
if you make scipts above while maya is running it wont work on mayas, 7.0 and later!
See maya does this on stratup.
check what files are available and put them in a lookup hash. Once this is done its done. Maya will NEVER do it again until it restarts. So what you have at start of maya is what you end up with for the entire session. this has been hinted above:
QUOTE
(maya does this once at every startup you can force maya to do this by calling rehash 7.0 and newer mayas only tough)
so if you just created the file while running maya you must:
rehash; (note never call this in your scripts as its as costly as restarting most of maya)
QUOTE
Can you explain MethodName(objectDatablock).
If i give objectDatablock there then how can i pass values to my perameter?
MethodName(objectDatablock, param1, param2....) // first param is just the object datablock
PS: it wouylnt by the way hurt for you to hit f1 as this all is exlained there in very fast to learn way.
QUOTE(Joojaa @ 09/25/07, 03:40 PM) [snapback]273825[/snapback]
you just call it!
procname();
in the above example i am calling like this but till the same error is there
QUOTE(Joojaa @ 09/25/07, 03:40 PM) [snapback]273825[/snapback]
rehash; (note never call this in your scripts as its as costly as restarting most of maya)
MethodName(objectDatablock, param1, param2....) // first param is just the object datablock
Till i cannot call my locale procedure in global procedure?
Thank you
QUOTE(CyberSoftHa @ 09/25/07, 03:38 PM) [snapback]273824[/snapback]
I am saving my scripts in the below path
C:\Doc~ and Sett~\h~\My Doc~\maya\7.0\scripts
Below is my script
Script Global:
CODE
global proc ThisIsGlobalProc()
{
print "\n ThisIsGlobalProc \n";
ThisIsLocalProc;
}
proc ThisIsLocalProc()
{
print "\n ThisIsLocalProc\n";
}
here i am calling my local procedure in global procedure but it is showing error
CODE
// Error: file: C:/Documents and Settings/hari/My Documents/maya/7.0/scripts/ThisIsGlobalProc.mel line 4: Cannot find procedure "ThisIsLocalProc". //
How can i call a local procedure in global procedure?
thank you.
How can i call
Ahh thats different thets just a syntax error.
the local proc needs to come before the global one to be defined at compile time.
QUOTE
rehash; what will this command do?
update maya to whats on your disk
QUOTE
what will be the value of objectDatablock?
its a databock that contains all public and private data in your object.
Yes, It is working. Thank a lot Joojaa.