PDA

View Full Version : Names and expressions


isoparmB
02-13-2007, 11:15 AM
Wouldn't it be great if expressions knew their own names? I feel like I'm trying to do something that appears to be undoable.

I have a master file which has an expression. This expression is supposed to switch connections between shaders on a specified shading group. I want to reference this file multiple times into a scene, and have the controller of one reference just alter the connections on that reference alone.

Problem is the existing workaround for mel commands in an expression in regards to naming, namespaces and such, which is to query the existance of a uniquely named node, dosen't work in this scenario because every one of these references will have the unique node. I want the references to be from the same file, but for each reference's own expressions to only access the contents of their own reference.

I can pretty much do this globally, say have a script that can switch all of the shaders of each instance change, but I want to individually control instances using an expression (as it seems the logical medium for setting up a conditional switch for a connectAttr command) tied to a controller. I'm aware that expressions are limited to renaming only those attributes which are directly connected to them at the node level, but it would just be so simple if expressions had something like a default variable that identified itself within itself. That way, you could associate it with a particular reference.

I guess my question is, it there any way, from within an expression, to at least query the connections of that expression's plugs so as to at least have a starting point of getting a name that I can parse?

brubin
02-13-2007, 01:42 PM
hi,

I'm not making too much sense right now of what you seemingly want to achieve, maybe it's because you're lost for the right words, or maybe you're lost in the complexity of your idea.

my 2-cent contribution in a nutshell at this stage would be: message-attribute!

i've learned to enjoy the benefits of those a great deal, in some script i even established message attribute connections between transform and its shape, just to make relations a bit clearer than any query to "listRelatives -s" could. may sound funny to anyone else, but to me it made, and still makes sense.

the point is,
while i thought about a reply to this your question i created a simple scene with a ball and a cone and a simple expression linking their translateX-attr.
(c1.translateX=b1.translateX)
I found i hadn't noticed before how only the node on the giving end (b1) has a direct link to the expression, while c1, the node receiving translateX from b1 is only connected to the expression via a unitConversion, which means - no direct link!
so i see your troubles there, same goes for transform and shape, in hypergraph they appear unrelated, which clearly is big *BS*, so maybe you can see now, why i chose to link'em via some customary "mother:offspring"-message-attribute.
makes nodehoppin' so much easier, if you can do loops like: if(`attributeExists "mother" "myTransformNode"`)
{
string $offspringNode = `connectionInfo -destinationFromSource "myTransformNode.mother"` ;
print ($offspringNode + "\n") ;
}

so,
this gives you manifold opportunities:


you can link each shaderGroup to the shader(s) you need switchable;
you can link each shape to the SG by your own design
you can link the expression to every node affected by the expression, or vice versa - link the nodes affected to the expression
HIH
s.

isoparmB
02-14-2007, 01:25 AM
Thanks Brubin. I was actually thinking of connecting the affected nodes to the expression that way, but my problem is this:

if(`attributeExists "mother" "myTransformNode"`)
{
string $offspringNode = `connectionInfo -destinationFromSource "myTransformNode.mother"` ;
print ($offspringNode + "\n") ;
}

This would work if it was the only object in the scene with this expression. But if I rename "myTransformNode" to something else, or if it get's renamed in the process of referencing (because we need namespaces) or importation, the name will not update on the expression because you were using a mel expression to access the connection info, and this does not directly link myTransformNode to the expression. I can account for the name using a wildcard with something like this:

if((`attributeExists "mother" "*myTransformNode"`) || (`attributeExists "mother" "*:*myTransformNode"`))
{
}


But if there are multiple references of this file in a scene, the expression will then see all "myTransformNode" objects.

Sorry if I wasn't being clear enough. The goal of the expression is to switch the connection of shaders on a given shader group, much like what render layers does with material overides. The expression would switch the outColor of a specified shader (say between a lambert and a useBackground) on a given shadingGroup which already has objects assigned to it. I wanted to set this up because reference files' render layers often break down when you assign additional layers on the shot file itself. I thought if I could pre-setup the shader overiding using this method it would keep render layers from breaking.

CGTalk Moderation
02-14-2007, 01:25 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.