ldunham1 explanation is bad, and it contains very bad advice. It has nothing to do with global procs, and that is not a issue in any case. ScriptJobs WILL NOT WORK, because scripJjobs get disabled on update, and using one would be suicide anyway.
The problem is:
vector $myLoc = xform -q -ws -t persp
;
That is a query, nodes are explicitly assumed not to query anything outside themselves. Nodes are assumed to bring nothing from the surroundings to themselves, and all their data is based on things they have inside themselves: the mechanism used to make this workable is connections, connections bring in info to the node, the nodes itself has nothing to do with the transport mechanism. Expressions are for all intents and purposes just that custom evaluation nodes. Now maya does not ever enforce said rules, because it MIGHT be useful to break the rules for some corner cases. Imagine a law that stated that all stealing is wrong, well it turns out that courts all around the world allow for corner cases where it is in fact totally legal to steal property of others if the stealing is for the greater good such as saving a persons life from a a imminent threat. This does not mean that the rule is not beneficial 99.99% of cases, and this also applies here.
Queries do not know when the value changes, they just know how to fetch the value. Connections on the other hand do 3 things:
- They inform the downstream nodes when their values are out of date
- Prune off calculations that do NOT need to do anything because they fail affect anything meaningful in the program
- Ensure things get executed in the right order, when the values are updated (along with ensuring maya does NOT go into a infinite loop)
So then how do you do the same thing as xform -q -ws -t? Well you either point multiplicate persp.t with persp.worldMatrix. As a easier alternative just parent constraint a world space transform to persp and use that as input (if you mark the transform as intermediate then maya will hide the node from outliner reducing clutter). Other alternatives exits as well.
However:
This expression is largely unnecessary and does the wrong thing for 90% of purposes. Only if you really use a a ray tracing lense shader does it really work out, or because you need some secondary ray effects (if tough you need both and this problem is visible in the reflections, which is generally not the case you need 2 particle systems). Because the 3d camera cheats a bit causing the direction to be planar instead of curved like in areal world, this means that to get things pointing your way its enough to just use a orient node at the instanced shape and no need for the per particle expression.