View Full Version : Mel Questions.
ambient-whisper 09-02-2002, 07:57 AM this will be my mel question thread:)
#1.) when creating objects using mel they usually have a name flag. but for some reason "CreateEmptyGroup" does not. is there anyway to introduce a null into the scene with a specified name/syntax ? so it would name the null "scene" and if there is already a null named scene it would make one named scene 1.
2.) how would i tell maya to take the current selection and then parent it to the null. so in the outliner they would be all below the null group?
thanks :)
|
|
alexx
09-02-2002, 08:12 AM
to #1:
if you dont have a name option in a command you can store the return value and use that one to continue:
these lines create the null with a name you want (myNull here)
string $name;
$name = `group -em`;
xform -os -piv 0 0 0;
rename $name "myNull";
to parent:
continue with that line:
parent (`ls -sl`) "myNull";
(parents the current selection to the null you just created
cheers
alexx
ambient-whisper
09-02-2002, 12:16 PM
thanks man:) worked like a charm :D
next question is a bit more advanced.
some commands like bevel...or split/connect edgerings with slide in maya seem not to be really all to interactive. they work. but then you have to dig into the channel box and use the virtual slider to use teh tool interactively.
well question is..
3.) bevel for example. is there anyway to make it so the command executes...but locks the offset to your mouse, so when you drag it from side to side the offset value changes interactively? until you press left click again to confirm the command? or if i then right clicked..i could cancel the command/script. so bevel would never be executed.
if there would be some clean reusable code. then adding this to a few scripts and linking the interactive properties that will make the tools much more enjoyable to use.
hmm. if a person were to build that part of a script. where would he go looking?
Changing to Maya AW?
But anyways, I have the exact same feature I'd like to know how to make. I think you could do it somehow with the command "scriptJob", I haven't looked at it yet (I'm not at that point yet with my current connect script, which isn't doing very well anyways) but it's used for such things, as running stuff when something is changed in the scene.
Dunno if this was any help, but what I've now read trough the MEL Command reference, "scriptJob" seems to be the first thing to look at.
Joojaa
09-02-2002, 05:54 PM
Originally posted by ambient-whisper
3.) bevel for example. is there anyway to make it so the command executes...but locks the offset to your mouse, so when you drag it from side to side the offset value changes interactively? until you press left click again to confirm the command? or if i then right clicked..i could cancel the command/script. so bevel would never be executed.
Yeah as you well know (would be supprised if you didnt) you can select the history channel in the channel box and then do this... now echo what it does when you do the selection and make one script job do this once the bevel is complete... :cool:
ambient-whisper
09-03-2002, 02:37 AM
new question:)
i often see a "-type" flag followed by "double3" what exactly is that?
( for example if i make an object come with a self made shader ( if there isnt one already and i want to setAttr shader.color its then followed by a -type double3 and then hte colour information. )
im kinda confused as to what the "-type double3" is there for...
ambient-whisper
09-03-2002, 10:13 AM
:)
been reading the user guide notes and came accross this:
if (test condition)
statement;
what i understand from this is that if whatever in the brackets is true...then the statement is executed.
so if i have something like this..
if ("GroupA.visibility" 1)
setAttr "GroupA.visibility" 0 ;
what im guessing here is that if teh groupA visibility is 1...then the bottom statement turns the group a off. except ..it only returns an error.
what am i doing wrong?
alexx
09-03-2002, 10:43 AM
i really recommend you to read the manuals and maybe a C book more carefully..
what you are looking for is:
if ((`getAttr groupA.visibility`) == 1)
{
setAttr ("groupA.visibility") 0;
}
Cool I was just typing my response up and was just about to press send when I noticed you had replyed already. Oh well, im too slow.
Here was my code anyhow. More or less the same
string $Visibility =`getAttr groupA.visibility`;
if ($Visibility == 1)
setAttr groupA.visibility off;
Alexx's one is better though.
- John
Actually, I know even faster method than the two already mentioned :)
Because if checks if something is true or not, or better, if something is 1 or 0, you don't need to type anything else than this:
if (`getAttr groupA.visibility`)
setAttr ("groupA.visibility") 0;
If you want to check something that's 0, rather than 1, you can but ! infront of the condition, like this:
if (!`getAttr groupA.visibility`)
setAttr ("groupA.visibility") 0;
Oh, and {}'s aren't neccesary if you use only one statement ;)
Thats great, thanks for that. Whilst im ok with the theory im not so hot in the faster and shortest way for doing things.
Cheers
- John
alexx
09-03-2002, 07:47 PM
Originally posted by hom
string $Visibility =`getAttr groupA.visibility`;
if ($Visibility == 1)
setAttr groupA.visibility off;
Alexx's one is better though.
- John
emm.. not really.. yours is the one how it should be done since it is far more readable :)
and about the -type flag on setAttr..
that one only tells maya what to expect.. if you omit it, maya expects a single value like a float or an integer..
but if you pass vector values to it, you need to tell maya, that the next three attributes are values.. otherwise it tries to see the second number as a new flag which results in an error..
cheers
alexx
boomji
09-04-2002, 06:51 PM
WT...why you terse little %$@# ;)
i dont seam to understand one thing in ambients lines please help
if ("GroupA.visibility" 1)
setAttr "GroupA.visibility" 0 ;
if the first line tests the truth of the statement,which is true(assuming the group was originally visible) .then why dosent the condition work...is it because it has to do with the syntax of that statement(the way maya wants it to be written) .or should i go and look up the three C books which are gathering dust just 5 steps away from where i sit :p
thanx
b
ambient-whisper
09-04-2002, 07:25 PM
it seems to be because i didnt define sides. so the visibility ( left side) has to be equal to 1 ( right side )
(`getAttr GroupA.visibility` == 1 )
Well it's just a syntax error. To make it work like that, you have to write
if ("GroupA.visibility" == 1)
setAttr "Groupblahblahblahblahb....
Actually, you propably need that getAttr put infront of that, so it looks like if (getAttr GroupA.visibility == 1), and because we have to actually run the supersmall script (getAttr GroupA.visibility), you have to put it in ``'s, so the final working syntax would be this:
if (`getAttr GroupA.visibility`== 1)
But, like I've said, if-conditional checks if something is true of false automatically, you don't need the "== 1" -part written at all, if you want to check if something is i.e. 4 (if (`getAttr GroupA.visibility == 4)), or if something is true and that visbility is 12 (if ($myVariable == 1 && `getAttr GroupA.visibilty == 12`))
Then you need the =='s.
And just plain = doesn't work, because that tells Maya to set the value to that, like
if ($myVariable = 10)
actually means "If the variable $myVariable has 10 set as it's value...", meaning the statement is always true.
This wasn't propably the most clear post, but I have a flu and all, so bare with me ;)
Edit: Apparently AW made it a few minutes earlier than me, oh well :)
bigfatMELon
09-05-2002, 05:08 AM
If we are striving for efficiency and readibility then I must toss my hat in the ring with:
if (`getAttr groupA.visibility`)
setAttr groupA.visibility 0;
No quotes or parenthesis are needed in the setAttr statement since groupA.visibility is a logical address and uses no concatenation. Alot of this stuff boils down to style and there are no real ground rules for this.
Working our way back, double3 is an often used yet little discussed datatype. You can look it up in the MEL docs.
And finally, the first question. You can do the whole thing in a single command as such:
group -n placeNameHere -em;
-jl
Per-Anders
09-05-2002, 06:34 AM
as this is clearly for a beginner programmer i don't think anyone quite made it clear why the "if" statement will work in exactly the same manner if it's put as either
if (`getAttr groupA.visibility`)
setAttr groupA.visibility 0;
or
if (`getAttr groupA.visibility`==1)
setAttr groupA.visibility 0;
and so for the absolute beginner a quick guide to conditional statments ("if" being one as any fule kno). Firstly why are those two peices of code identical as far as Maya is concerned? Because the "if" conditional statment as you first said tests whether what is inside the brackets is true or false, what you may not know is that in programming logical true is equal to 1 (false usually being 0, or null).
So why does this work? And why does :
if (`getAttr groupA.visibility` 1)
setAttr groupA.visibility 0;
not work?
Simply down to the way Maya looks and "parses" the code. When the "if" statment is evaluated Maya does the following, firstly it evaluates the individual blocks inside of the single quote marks, thus 'getAttr groupA.visibility' is the first thing that goes into the Mel parser, what comes out is the value of this statement, we know that the command getAttr [object.attribute] returns a value, and in this case it returns the value of groupA's visibility. Maya then substitutes the blocks with their evaluated values... thus if('getAttr groupA.visibility' 1) turns to if(1 1) you can probably begin to see why this wouldn't work... if it helps think of what would happen if you tried to put the value "1 1" into any objects x y or z value... either the object will go to 0 or it will ignore what you just typed, that's because this returns an error, it wont evaluate to 11, it doesn't equal 1 (true), so it can only equal void (false).
After parsing the blocks in the quotes Maya will parse the blocks in the brackets. Now we come ot logical operators, these are == (equals), > (higher than) < (lower than) => (higher than or equal) <= (lower or equal) != (inequal). If you were to write myVariable=9==9; then myVariable would have the value of 1 in it, this is because 9==9 evaluates to true (or 1). If you were to write myvariable=9==8; then myvariable would have the value of 0 in it. So when Maya's Mel parser evaluates what's left inside the brackets if you have:
int myVariable=1;
if (myVariable==1)
veblah veblah veblah
Maya will interpret this to
int myVariable=1;
if (1)
do this....
So because the "if" statement will only execute the block of code after itself (that is either the next line, or the next lines held between curly brackets { code here } ) if what is inside the brackets evaluates to true or to put it another way 1, then in this case the code will be executed because the value in the brackets comes out as 1 (true). Ok so that might have been pretty hard to get your head around, but hopefully it will have explained why your if statements work, and perahps now you will be able to go back and see why the top two examples come out with the same result and why the original statement wouldn't have worked (as "1 1" does not equal 1).
Sorry AW, but can I borrow your thread for a while? Thanks ;)
Just want to ask these few questions, I think it's better to ask here than make a new topic... but anyways:
1. So is it possible to have a variable sized matrices? It doesn't bother me if it's some weird hack, as long as it works.
And if there isn't, could I somehow "emulate" matrices with arrays? Or would it just turn out to be a matrix again?
2. (The more important question) Is it possible to assign a variable (array) with tons of stuff, at the start of Maya, and I could use that in my script?
Hmmm, well that wasn't very good explanation... well, I'll tell you the whole situation:
Ok, what I'm doing is, is to put the syntax of polySplit to an array. I was doing it by a simply:
string $blahblah[]; = "polySplit -theRightFlah -AnotherFlag"
for (Imaginehereaniceforsyntax)
$blahblah = $blahblahb + " More blahblahblahb";
eval ($blahlbahl)
But, imagine what happens when you do that with >100 edges? Yes, it get's very slow.
Well, what I'm trying to do, is assign the right flags and everything to an array at the start of Maya, and then I could just add the edgenumbers to the array, and wouldn't need Maya to add tons of stuff hundreds of times.
Is this possible?
Or actually, is copying an array (If it's veeeeery long) slow task? Faster than making that for loop everytime though?
Heck, I think I just answered myself :)
Oh well...
Edit: Just remembered another question:
3. Is there any easy way to know the new edges made by polySplit? Or do I have to figure 'em out somehow with the face positions and stuff?
ambient-whisper
09-05-2002, 01:48 PM
mdme_sadie: that was extremely informative. thank you! :)
bigfatMELon
09-05-2002, 04:44 PM
1. So is it possible to have a variable sized matrices? It doesn't bother me if it's some weird hack, as long as it works.
And if there isn't, could I somehow "emulate" matrices with arrays? Or would it just turn out to be a matrix again?
MEL provides no dynamic matrix ability. Fortunately, I do. Download cListTools from highend3d. It's a set of functions (much like my stringTools and arrayTools collection) that allows string arrays to be converted to string notation and back. So, you can do this sort of thing:
string $oneArray[] = {"one", "two", "three"};
string $twoArray[];
string $cList = `cListCreate $oneArray`;
// Result: {"one", "two", "three"} // <-- this is in string notation
Then you can stuff the resulting $clist into a conventional string array as such:
$twoArray[size($twoArray)] = $cList;
You can then do the reverse when you want to access the data from one of the big array:
$oneArray[0] = `cListToArray $twoArray[0]`;
There are other tools included to allow to work with cLists without having to always convert back and forth into string notation, like getting the size, adding and deleting items and getting the index of an item within the compound array.
As for a new edge made by polySplit, it will always be numbered one greater than the total number of edges prior to the operation.
-jl
I'm so ill right now (flu), that I didn't understand half of your post BFM, but I'll check out those scripts when I get better, thanks! :)
Oh and that polySplit observation helped too, I should have thought of that myself ;)
boomji
09-05-2002, 06:03 PM
hey dudes,
thanx.i love to learn this way,heck we should have a mel forum here as well :).
it's a pity(actually blessing in disguise) sven got a new job. he was going to start a melbot war right here...gwaahahahaha.he's got the dvd and stuff.
ah well !!! thanx again guys. now i'm in a very MELoncholy mood...hehehhe.
b
CGTalk Moderation
01-13-2006, 03:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.