PDA

View Full Version : Help a beginner! Script to Isolate Select Object


davidkenley
05-17-2010, 07:57 PM
I'm looking for help with a writing a basic MEL script. I'm really new to it so I'm totally lost although I do have experience in C#.

I built a simple MEL script that copies the function of the Isolate Select menu option (as I'd rather have a button instead of navigating the menus).

However, I want to improve it by making a version where if I have a face, edge or vertex on an objected selected when the isolate select button is pushed, it won't isolate everything except the selected face, edge or vertex, it will isolate the whole object from the rest of the scene.

So my question is, is there a way to query the selection and return the object (eg pCube1), instead of the string with the face for example (pCube1.f[4]). Or is the way to proceed to parse the returned string down to the object and proceed from there?

This is my code so far (just replicating the isolate select function as is from the menu)...

string $isPanel;
$isPanel = `getPanel -wf`;
isolateSelect -s (1-`isolateSelect -q -s $isPanel`) $isPanel;
isolateSelect -as $isPanel;

Thanks.

splinta
05-18-2010, 09:24 AM
Hi

I recently found out that this:

ls -sl -o -dag -s;

will select the shape node no matter what u have selected. then u can just pick walk up to the objects transform node with

pickWalk -d up;

splinta
05-18-2010, 09:25 AM
Hi

I recently found out that this:

ls -sl -o -dag -s;

will select the shape node no matter what u have selected. then u can just pick walk up to the objects transform node with

pickWalk -d up;
how this helps

jonne
05-18-2010, 11:22 AM
I usually do stuff in python so my approach in mel might not be the best but this should work:


string $sel[] = `ls -sl`;
string $tempArray[];
$tempArray = stringToStringArray($sel[0], ".");
select $tempArray[0];

rahulsg2901
05-18-2010, 03:26 PM
I'm looking for help with a writing a basic MEL script. I'm really new to it so I'm totally lost although I do have experience in C#.

I built a simple MEL script that copies the function of the Isolate Select menu option (as I'd rather have a button instead of navigating the menus).

However, I want to improve it by making a version where if I have a face, edge or vertex on an objected selected when the isolate select button is pushed, it won't isolate everything except the selected face, edge or vertex, it will isolate the whole object from the rest of the scene.

So my question is, is there a way to query the selection and return the object (eg pCube1), instead of the string with the face for example (pCube1.f[4]). Or is the way to proceed to parse the returned string down to the object and proceed from there?

This is my code so far (just replicating the isolate select function as is from the menu)...

string $isPanel;
$isPanel = `getPanel -wf`;
isolateSelect -s (1-`isolateSelect -q -s $isPanel`) $isPanel;
isolateSelect -as $isPanel;

Thanks.

check out this code


$aPanel = `getPanel -withFocus ` ;
$isoStatus = ` modelEditor
-query
-viewSelected
$aPanel ` ;

if ($isoStatus ==0 )
{
enableIsolateSelect $aPanel 1 ;
isolateSelect -state 1 $aPanel;
}
else
{
enableIsolateSelect $aPanel 0 ;
isolateSelect -state 0 $aPanel;
}

davidkenley
05-18-2010, 05:00 PM
Hello All,

Thanks very much for the help.

splinta, that's good to know, I'll keep that in mind in future.

jonne, your code didn't function as I wanted, but the approach was what I was trying to do so it was good to see how I'd code something like that in future.

rahulsg2901, your code works, but it just seems to duplicate the isolate select code, and does not have the extra function that I wanted. I'm sorry, perhaps I didn't explain what I wanted clearly enough. Thanks also for writing it long hand, the short hand notation may be efficient but its hard to understand at when you're learning!

Through a lot of trial and error a friend of mine at school managed to get the code functioning as I wanted. Apparently using the -ado was the key to getting the root of the object. I still don't know if it's the best way to do it, but it seems to work!

Here's the code if you're interested, if you create a few objects, select a face on one and then hit the button it'll isolate the object and not just the face on the object now.

$sH = `ls -hl`;
string $isolateSelectPanel;
$isolateSelectPanel = `getPanel -wf`;
isolateSelect -s (1-`isolateSelect -q -s $isolateSelectPanel`) $isolateSelectPanel;
isolateSelect -ado $sH $isolateSelectPanel;

Thanks again for all your help.

rahulsg2901
05-19-2010, 07:30 AM
Hello All,

Thanks very much for the help.

splinta, that's good to know, I'll keep that in mind in future.

jonne, your code didn't function as I wanted, but the approach was what I was trying to do so it was good to see how I'd code something like that in future.

rahulsg2901, your code works, but it just seems to duplicate the isolate select code, and does not have the extra function that I wanted. I'm sorry, perhaps I didn't explain what I wanted clearly enough. Thanks also for writing it long hand, the short hand notation may be efficient but its hard to understand at when you're learning!

Through a lot of trial and error a friend of mine at school managed to get the code functioning as I wanted. Apparently using the -ado was the key to getting the root of the object. I still don't know if it's the best way to do it, but it seems to work!

Here's the code if you're interested, if you create a few objects, select a face on one and then hit the button it'll isolate the object and not just the face on the object now.

$sH = `ls -hl`;
string $isolateSelectPanel;
$isolateSelectPanel = `getPanel -wf`;
isolateSelect -s (1-`isolateSelect -q -s $isolateSelectPanel`) $isolateSelectPanel;
isolateSelect -ado $sH $isolateSelectPanel;


Thanks again for all your help.


Ur script work fine for single object only but it gives error if multiple objects selected (any component/object mode)

Code from @splinta (ls -sl -o -dag -s) its good code I do this in other way this code is good & from ur code that (-ado) I modify script. Its work fines in any cases.





//SELET OBJET NOT A COMPONENT
string $ObjSel[] =`ls -selection -objectsOnly -dagObjects -shapes`;
// GET MODEL PANEL
$aPanel = `getPanel -withFocus ` ;
$isoStatus = ` modelEditor
-query
-viewSelected
$aPanel ` ;

// TOGGLE SELECTION
if ($isoStatus ==0 )
{
enableIsolateSelect $aPanel 1 ;
//LOOP THOUGH EACH OBJECT
for ($eachObject in $ObjSel)
{
isolateSelect -addDagObject $eachObject $aPanel;
}
isolateSelect -state 1 $aPanel;
}
else
{
// GET NORMAL VIEW
enableIsolateSelect $aPanel 0 ;
isolateSelect -state 0 $aPanel;
}

rahulsg2901
05-19-2010, 03:40 PM
Yes, I guess I didn't test it thoroughly enough. Your code now does exactly what I wanted.

Thanks for posting again.


Welcome:) :bounce:

davidkenley
05-19-2010, 03:41 PM
Yes, I guess I didn't test it thoroughly enough. Your code now does exactly what I wanted.

Thanks for posting again.

ewerybody
05-20-2010, 02:06 PM
sorry for piling it up some more .. I just wanted to share this line with you:
enableIsolateSelect modelPanel4 (!`isolateSelect -q -state modelPanel4`);I seem to work only in modelPanel4 so its good for me... But I think this is really a line from Maya built in somewhere.. *shrug*

rahulsg2901
05-20-2010, 02:38 PM
sorry for piling it up some more .. I just wanted to share this line with you:
enableIsolateSelect modelPanel4 (!`isolateSelect -q -state modelPanel4`);I seem to work only in modelPanel4 so its good for me... But I think this is really a line from Maya built in somewhere.. *shrug*

Your code is work but in only in perspective view & also it isolate only component davidkenley want to isolate object if any component selected

r4inm4ker
05-20-2010, 03:33 PM
I think the post in my blog does exactly what you want. it's in chinese though,but you can just browse to the code part

http://maya-tricks.blogspot.com/2009/04/blog-post.html

rahulsg2901
05-20-2010, 04:07 PM
I think the post in my blog does exactly what you want. it's in chinese though,but you can just browse to the code part

http://maya-tricks.blogspot.com/2009/04/blog-post.html

Your code works in only either in component mode or object mode but if you select few component & some object after 3 hit it loose the object it shows only component & once you enter in isolated mode with component selected you canít get in the object mode using right click marking menus check out code I posted it doesnít have this kind of problem till now

CGTalk Moderation
05-20-2010, 04:07 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.