View Full Version : get object name
twilightened 07-02-2008, 02:52 PM Hi,
Given that an object has translate values say, 10, 10, 10 in x, y and z axis respectively. Is it possible to find the object name given this information.
BRgds,
kNish
|
|
there are probably smarter ways to do this, but here you go...
the x,y and z values are the ones you want to search for, the tolerance is there to compensate for maya's rounding errors and it returns the objects that return true to the given criteria..
global proc string[] FO_FindObject(float $fX, float $fY, float $fZ, float $fTolerance)
{
string $saOriginalSelection[] = `ls -sl`;
select -all;
string $saMatchedObjects[];
// get all the poly objects in the selection
string $saPolyObjects[] = `filterExpand -sm 12`;
// do the min and max values to compensate for rounding errors
float $fX_Min = $fX - $fTolerance;
float $fY_Min = $fY - $fTolerance;
float $fZ_Min = $fZ - $fTolerance;
float $fX_Max = $fX + $fTolerance;
float $fY_Max = $fY + $fTolerance;
float $fZ_Max = $fZ + $fTolerance;
for ($sObject in $saPolyObjects)
{
float $faXForm[] = `xform -q -ws -t $sObject`;
if ( $faXForm[0] >= $fX_Min && $faXForm[0] <= $fX_Max &&
$faXForm[1] >= $fY_Min && $faXForm[1] <= $fY_Max &&
$faXForm[2] >= $fZ_Min && $faXForm[2] <= $fZ_Max)
{
$saMatchedObjects[size($saMatchedObjects)] = $sObject;
}
}
select -r $saOriginalSelection;
return $saMatchedObjects;
}
FO_FindObject(10.0, 10.0, 10.0, .001);
NaughtyNathan
07-03-2008, 09:30 AM
good work Norb, however, you assume he only wants to find poly mesh objects? it would be better to simply look for transforms at the given position so it'll work on ANY object in the scene...
(as an aside, try not to change the selection state in a MEL script unless absolutely necessary or as a function of the script. Changing the selection causes all sorts of internal computation and state switching regarding undo stacks, screen refreshing, etc.. and only serves to make your scripts run slower, potentially use(waste) more memory and degrade your overall performance...! sure, this is mainly academic and may not be that noticable on smaller examples, but it's a good habit to get into!)
:nathaN
CGTalk Moderation
07-03-2008, 09:30 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.