View Full Version : Distance and selection problem...

11 November 2011, 09:43 PM
Hi there;

I'm a new user for mel , i was working on maxscript for 5 years and i was comfortable with it.
But now i'm planning to switch my tools to a new maya pipeline...

In this case , i'm trying to explore basic mel command but there are some parts for me to unmatched with maxscript...
here they are;

.imagine that there are lots of geometry in our scene and some of thems name is start with scene_xxx , in max script i can select them as " select $scene_* " but i couldnt see any similiar method in mel to select with a joker character... how can we solve this?

.and second problem is with distance calculations...
"distance $node1 $node2 " method was giving me the distance of two nodes in maxscript but as i see in mel , i need to use distanceDimension tool to read it.
With this tool i can read the distance in attribute of it but i couldnt reach it in mel... also i couldnt see it in mel commands documents. What i need to read distance? or is there a code similiar with maxscript...

in addition to their , there is not a visual ui editor for mel! this will kill my time to create gui for animators, isnt there any way for this? (maybe with an external software or tool)

I'm sorry if seems like a negative user but im sure that mel will make me stronger than maxscript in future :thumbsup:

Thank you in advance, best regards Eren...

11 November 2011, 10:17 PM
Here is some guide just for your case:

About your particular questions:
You can select objects by wildcards like this:

// List all objects named "scene_*"
select -r `ls "scene_"`;

Note that these are actually two commands and the backquotes (`) are telling the select command to use
the return value of the list (ls) command as an argument.

The distance can be calculated without nodes, just by vector maths

vector $v1 = `xform -q -ws -a -t object0`;
vector $v2 = `xform -q -ws -a -t object1`;
$dist = mag($v1-$v2);

For UI building you can use QT Designer, although it's much better to learn how to build it yourself

11 November 2011, 11:50 PM
Hey Nickolay , thank you for tips!
i ve just tried QT designer, it works perfect thank you!
otherwise, distance and selecting codes seems like working but when i checking them in mel commands document. For example there is not a list (ls) command on select section. Also it seems like there is not a command like "vector"...

i'm trying to find my way on mel commands document but im doubt that does it make my way harder to learn...

11 November 2011, 12:07 AM
select -r `ls "scene_*"`;

Note that these are actually two commands and the backquotes (`) are telling the select command to use the return value of the list (ls) command as an argument.

And "vector" is a variable type, not a function.

Hope this helps.


11 November 2011, 12:18 AM
oh Risto sorry i missed it!
now its clear for me thank you...

And sorry for too many asks but there is one last example that i want to test...

how should we use this maxscript in mel?

//there are 6 cubes in scene
select "cube*" ;
//6 cubes selected
$[2].position.x = $[6].position.x;
//match the position x of 2th selected cube with the 6th cube...

11 November 2011, 02:20 AM
I adjusted this a little... a cube default name in Maya comes out pCube1, pCube2, etc. But in MEL, pCube6 will be referenced by index 5, pCube2 by index 1.

string $cubes[]=`ls -tr "pCube*"`;
setAttr($cubes[5]+".tx", getAttr($cubes[1]+".tx"));

Note that on the ls command I used the -tr option, otherwise you would be getting both the transform and the shape nodes, but the ".tx" attribute is only available from and applied to the transform node. The ".tx" attribute is the short name, you could also use ".translateX" if you want less obfuscated code.

In the technical docs is a listing of all the standard Maya nodes and their attributes. Note that getAttr() and setAttr() will require and return different data types (int, string, float, or arrays, etc.) depending on the type of attribute you are getting or setting, and that a mismatched type will raise an error at run time.

<* Wes *>

11 November 2011, 06:51 PM
Hey erensaritas, I know that the original question was regarding MEL, and you've gotten some wonderful responses...but since you're new to scripting in Maya, I thought I'd also throw some Python code your way:)
First import Pmyel:
from pymel.core import *

#To select all objects in a scene via some sort of filter
select(ls("scene_*"), r=True);

#obtaining distance between two objects

obj1 = PyNode("obj1")

obj2 = PyNode("obj2")

dist = obj1.t.get().distanceTo( obj2.t.get() )

11 November 2011, 10:17 PM
Hi again friends;
firstly thank you for your responses on my problems, im very glad for them!

thank you so much now im clear with * character usage...

Those codes are seems like more similiar to maxscript , so you mean that it will be better to focus on python for me ?

best regards!

11 November 2011, 11:22 PM
Well...I'm not too familiar with maxscript. So I don't know what type of transition you'll be making. But if you feel more comfortable with the python syntax I showed you, then look make sure you look into pymel. It comes with all sorts of goodies like the Vector.distanceTo(Vector) procedure I used earlier. As of maya 2011, pymel comes preinstalled with maya. And if you have earlier versions...I think back to 2009, there are instructions on their website on how to install.

Good luck!

11 November 2011, 10:57 PM
Thank you so much gtbull80;
as i see for now phyton and mel are close with each other. i mean both of them are diffrent with maxscript :)
So i will continue with mel i guess...

And i have one more silly question! im sorry for that again but i couldnt understand why it becomes...

when i write "pCube1.scaleX = 10" to the expression editor it works correctly, but when i jump to script editor and paste the same code it says;

// Error: pCube1.scaleX = 10; //
// Error: Line 1.20: Invalid use of Maya object "pCube1.scaleX". //

i couldnt understand that why it doesnt work on script editor? what is the code grammer diffrance between script editor and expression editor?

11 November 2011, 01:00 AM
The expression editor works differently than the script editor. In the expression editor, a statement like pCube1.scaleX = 10; is converted to an expression node with a value of 10 and a connection to the pCube1 node scaleX input.

In both the script and expression editors, you could use setAttr("pCube1.scaleX", 10); (note that MEL syntax requires the object.attribute name be in quotes) and get the same result, although a previously made connection will lock the attribute, so if you already have a connection, then the setAttr() will fail with "// Error: line 1: setAttr: The attribute 'pCube1.translateX' is locked or connected and cannot be modified."

<* Wes *>

CGTalk Moderation
11 November 2011, 01:00 AM
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.