No just using expressions for this is abit wierd.
Okay you should understand that tehres a HUGE difference between a expression and MEL, its like night and day. Even their syntax differs, somewhat.
Expression nodes are however capable of running mel inside them, because they do kow the whole mel parser routine. That however does not mean you should call mel inside a a expression, infact you should abstain form doing so as much as humanly possible. Why should you avoid mel inside a expression?
[ul][*]it does not get connected to the dg, thereby depriving maya of any knowlege on how its related to the big picture.
[*]it is possible to break the inner workings of dg with a misplaced expression.
[*]It has a potential on being very very slow because its initiated outside rhe normal working of the dg, infact some melsyntax stuff like getAttr will force the graph to re evaluate, cusing a ppossibe extra loop, making maya do 2 times the work for each time its called.
[*]Nodes woud not be able to detect renaming, wich would lead to nonworking expressions if the element wads renamed or referenced. The node cat even realy rectify this because it does not know who it is. (a node should not know hwo he his by the way or anything of the big picture thats their entire purpose)
[/list]
Okay now in your case theres absolutely NO need for any of this! Its just pure stupid! just generate the data once. Your version generates the data for ech and everuffreame in esistence.
What you do is a mel loop, that is run on demand, that is ONCE when you have all your lights placed. A samle fragment of mel would look like this NOTE THIS IS NO EXPRESSION Its mel execute in the script editor:
{
string $spot;
$spots=ls -type spotLight
;
for($spot in $spots){
// uncomment next 2 lines if you need thetransform to host this, not shape
// altough shape is more likely for mtor
// $spotTemp=listRelatives -parent $spot
;
// $spot=$spotTemp[0];
$end=match("[1234567890]*$", $spot);
if (!(attributeExists "num" $spot
)){
addAttr -ln num -at long -dv ((int) $end) $spot;
}else
setAttr ($spot+".num") ((int) $end);
}
}
offcourser now it wouldnt do this automaticaly, but it could you could either set tjis a s a prerender script of somekind OR make a scriptjob to watch the change of names. But it so happens you dont need this.
In MTOR theres realy no need for this mtor can handle it on push to rendertime jut like a prerender script, wich makes it even easier. before render mtor parses trough a tcl script that is run, the variable $OBJNAME contains the name of the object in question. Now with a bit of tcl you can easily derive the end off the objname... But thats more of a topic for a tcl forum. Read your MTOR manual and then a tcl manpage.
Edity made the script a wee bit more roboust.[/ul]