View Full Version : change reference name

07 July 2012, 06:56 AM
Hi all,

I wrote a nice MEL Script that I use to control my ship.
But now I have a problem with referensing.

-sbc "setKeyframe AframeCurve.translateY" -el "Meter" -min -19 -max 0 -sbd true -i "Flag.png" myAframeSliderCtrl`;
connectControl myAframeSliderCtrl("AframeCurve.translateY");

this is just 1 line from my script but here comes the problem.
AframeCurve is a curve that I use to control stuff. But I start a new file, then I reference the file with the ship model in it. Now the AframeCurve is called FINAL_SHIP:AframeCurve.
So basicly my script isnt working anymore.

what can I do to prevent this? Should I change the names of the referenced files or is there some kind of script that can put FINAL_SHIP: in front of everything?

Help plz


07 July 2012, 03:55 PM
You can use the namespace flag for the file command to change the names of the referenced files:

-namespace(-ns) string file:///usr/autodesk/maya2011-x64/docs/Maya2011/en_US/gfx/edit.gif
The namespace name to use that will group all objects during importing and referencing. Change the namespace used to group all the objects from the specified referenced file. The reference must have been created with the "Using Namespaces" option, and must be loaded. Non-referenced nodes contained in the existing namespace will also be moved to the new namespace. The new namespace will be created by this command and can not already exist. The old namespace will be removed.

Something like:
file -r -ns "FINAL_SHIP" "";

Hope this helps!

07 July 2012, 08:00 PM
you should not write scripts that reference nodes directly by name. you should write your script to take any name as an input and pass it along to the commands that perform the hook up.

instead of this:
setAttr "pSphere1.translateX" 10;

you should do this:
string $node = "pSphere";
setAttr ($node + ".translateX") 10;

now it doesn't matter if "pSphere1" is changed to "REF:pSphere1", the rest of the code will work just fine.

08 August 2012, 09:15 AM
Thnx for your responces.

But I just changed my script.
Since I know it is going to be called REF_SHIP.. I changed everything to REF_SHIP:sphere1 for example.

but that node thingy is realy handy :)


08 August 2012, 12:58 PM
well after an other try i just f*cked up again. Now trying that option .$node

but Im stuck.

When do i need to put it between ( ) and when ""?

and a other question what does a Euro sign mean in the error?

string $MainH = "MainhookBlock";
string $MainMove = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "Up Down" -field true -buttonLabel "SELECT" -bc "select -r $MainH";
-sbc "setKeyframe ($MainH +.translateY)" -el "Meter" -min -1000 -max 0 -sbd true -i "Flag.png" MainhookSliderCtrl`;
connectControl MainhookSliderCtrl ($MainH +".translateY");
// Error: string $MainMove = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "Up Down" -field true -buttonLabel "SELECT" -bc "select //
// Error: Line 43.9: Syntax error //

08 August 2012, 04:10 PM
To make the code a little easier to read, you should first create the floatslidergrp, and then modify it afterwards.

string $node = "pSphere1";
string $sliderGrp = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "Test" -field true -buttonLabel "SELECT"`;

string $command = ("setKeyframe " + $node + ".translateX");

floatSliderButtonGrp -edit $sliderGrp -sbc $command;

08 August 2012, 07:30 AM
To be honest... I think my line is better to read, less looking forward and back to figure out wich string is what. ( atleast thats my opinion)

well im almost done.
but im stuck at a big line now, On the buttoncommand several things have to happen.

string $S1Kable = "S1kable";
string $S1Anker = "S1Anker";
string $S1ANkerCrv = "S1Anker_curve";
string $S1Joint = "S1Joint";
string $S1control = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "S1" -field true -buttonLabel "DP OFF" -bc {" setAttr $S1Kable +.visibility 1; setAttr $S1Anker +.visibility 0; setAttr $S1ANkerCrv +.visibility 1"}
-sbc {"setAttr $S1Kable +.visibility 0; setAttr $S1Anker +.visibility 1; setAttr $S1Joint +.rotateY 0; setAttr $S1ANkerCrv +.translate 0 0 0; setAttr $S1ANkerCrv +.visibility 0"}
-el "degree" -min -68 -max 77 -sbd true -i "DP Off.png" S1SliderCtrl`;

Now I know there have to be "" and ( ) somewhere... but when I add "" i get a problem with the first " after the -bc {

could you plese explain when and where I need to use these things?
** EDIT**
Hmm... well Im testing the whole script as a reference but it is not working.
// Error: Unable to resolve attribute 'CONTROLS.BOOM'. Make sure specified attributes are valid.
I think because it doesnt have the ref name.

08 August 2012, 01:26 PM
TDGirl im trying your option also but I get the error that I can't change referance names. :(

08 August 2012, 02:30 PM
the problem with one big line, is it very hard for other people to understand what is going on.

another reason for splitting complex argument assignments up over multiple lines is to make it easier to keep track of the scope - i.e. to make sure you are properly opening and closing strings, are properly escaping special characters, etc.

as to you questions, the code sample you pasted doesn't have any reference to an attribute named CONTROL...can you provide a little bit more context?

I haven't used MEL for awhile, but I don't recall using "{}" brackets to pass strings as an argument.

08 August 2012, 03:00 PM
TDGirl im trying your option also but I get the error that I can't change referance names. :(

if it's a referenced file, change the namespace with the edit flag:

file -e -ns "myNamespace" "";

02 February 2013, 08:53 AM
Sorry to come back on this but im still stuck.
For a while I had a workaround but now it doenst work anymore.

when I try with the option :
string $node = "pSphere1";
string $sliderGrp = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "Test" -field true -buttonLabel "SELECT"`;
string $command = ("setKeyframe " + $node + ".translateX");
floatSliderButtonGrp -edit $sliderGrp -sbc $command;

I get the error :
// Error: line 6: Flags must come before objects: -sbc //

But I wonder, when you make sphere, and save it as TEST.mb
Then you make it a reference, then the name of the sphere is: TEST: pSphere1

why wouldnt it give the same problem as I have?
string $Aframe = "AframeCurve";
string $sliderAframe = `floatSliderButtonGrp -cw 2 40 -cw 3 240 -label "A-Frame" -field true -buttonLabel "SELECT" -bc "select -r $Aframe;"
-sbc "setKeyframe $Aframe +.translateY" -el "Meter" -min -19 -max 0 -sbd true -i "Flag.png" myAframeSliderCtrl`;
connectControl myAframeSliderCtrl($Aframe +".translateY");

the error I had was
// Error: Unable to resolve attribute 'CONTROLS.CRANE'. Make sure specified attributes are valid. //

02 February 2013, 01:49 PM
sorry to kick this up again but I figured out what I can do.

At windows> general editors>namespace editor
Select the namespace and hit delete.
Then it will ask what you want to do with it, if you hit delete here, it will say you can't do it because it is a reference.
But when you hit merge with parent or merge with root. you will get the normal names back. :)
Instead of trying to figure out how to fix it in MEL I just keep it to this.

CGTalk Moderation
02 February 2013, 01:49 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.