Home Technical Talk

Maya MEL - Expression doesn't update/evaluate on changing attribute.

polycounter lvl 2
Offline / Send Message
Pryor_MartinHuetter polycounter lvl 2
Hello awesome polycount folks, I'm currently digging into more advanced rigging techniques, just started scritping and I've a probably easy mel scripting question. I want to have a single Enum attribute "slider" that changes the translation of an object (to later on snap locators to each others and switch through different systems). I'll demonstrate what I want to achieve through an example:
By the way I'm by no means a coder, I've almost no experience in programming.

little gif, easy enough so far:


 -Super basic expression code:

<p>if (pCube2.State == 0){</p><p><br></p><p>	pCube2.translateX = -4;</p><p><br></p><p>}</p><p><br></p><p>else if (pCube2.State == 1){</p><p><br></p><p>	pCube2.translateX = 0;</p><p><br></p><p>}</p><p><br></p><p>else {</p><p><br></p><p>	pCube2.translateX = 4;</p><p><br></p><p>}</p>
Bad thing is now the actual values of the cube are locked for the user, and it just feels messy.

So I found through some autodesk educational video the command "xform" with which I can actually catch and instert the local or world positions of objects into each other, and values stay unlocked, awesome!... well no.... now the enum attribute doesn't do anything anymore, or doesn't update, I have to hit "edit" in the expression editor to get a change. Thats aboult how far I am able to code lol, no idea why this doesn't work, I looked up some mel videos and maya docs but can't figure this out.

gif and code of my current state:


 -Code:

<p>if (pCube2.State == 0){</p>
<p> //(pCube2.State <= 0)</p>
<p><br></p>
<p>	//pCube2.translateX = -4;	</p>
<p><br></p>
<p>	$StateA = `xform -query -objectSpace -translation pSphere1`;</p>
<p>	xform -objectSpace -translation $StateA[0] $StateA[1] $StateA[2] pCube2;</p>
<p><br></p>
<p>}</p>
<p><br></p>
<p>else if (pCube2.State == 1){</p>
<p>      //(pCube2.State >= 1 && pCube2.State <= 1.9)</p>
<p><br></p>
<p>	//pCube2.translateX = 0;</p>
<p><br></p>
<p>	xform -objectSpace -translation 0 0 0 pCube2;</p>
<p><br></p>
<p>}</p>
<p><br></p>
<p>else {</p>
<p><br></p>
<p>	//pCube2.translateX = 4;</p>
<p><br></p>
<p>	$StateB = `xform -query -objectSpace -translation pSphere2`;</p>
<p>	xform -objectSpace -translation $StateB[0] $StateB[1] $StateB[2] pCube2;</p><p><br></p><p><br></p>
<p>}</p>
I even tried to clamp the if conditions because I know the enum isn't really a list in maya and uptades crazy if you middle mouse button drag within the viewport in values with 2 decimals like:

setAttr "pCube2.State" 0.13;
setAttr "pCube2.State" 0.11;
setAttr "pCube2.State" 0.3;
setAttr "pCube2.State" 0.24;
setAttr "pCube2.State" 0.54;
setAttr "pCube2.State" 1.81;

Didn't do anything :/

Thanks for the read! Thanks for every comment to this and have a nice day! - Martin

Replies

Sign In or Register to comment.