cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Allow simple calculations in attribute entry fields.

Allow simple calculations in attribute entry fields.

It would be very useful to be able to do quick calculations in attribute entry fields.  For example if I have something rotated to 275 degrees and I want to double it it would be nice to be able to click in the field and just type "* 2" and hit enter and the value would be updated to 550.  There would be no history or expression created here.  It's just doing the calculation and then replacing the existing number.  Nuke has a feature like this and it's a really quick and simple way to update parameters and experiment with different values.

10 Comments
jwlove
Advocate

I think you can already do this... at least in the translate/rotate/scale attrs you can.

 

Try "*= 2" which is the programming way to say "take something, multiply it by 2 and place the resulting value back in it's place" (this is typically done with a variable - ie: "myVariable *= 2" would take whatever value 'myVariable' has, multiply it by 2 and then change the variable's value to the result).

 

I'm pretty sure you can use that everywhere on numeric attrs, but it would be nice if it was updated so you could if there are some situations you cannot...

zewt
Collaborator

Wow--that might qualify as Maya's most obscure feature.  I've used After Effects's equivalent of this, but I've been copying numbers out to a calculator and back in for years with Maya.

 

Only works in the CB, though.  It would be much more useful if it worked in the AE (and AE-like dialogs, like render settings).  You can type =text to create n expression, but it won't let you type -=.

 

berjb
Contributor

It does indeed work only in the channel box (thanks for that.. I had no idea).. but this is terrible syntax and UX.  it's more verbose than it needs to be and you can't do things like 1/<current value> or 10-<current_value> -- it only allows changes relative to the current value.

 

This sort of thing should be allowed everywhere a numerical value can be entered throughout Maya. and it should allow arbitrary mathematical expressions.  I do this all the time and as zewt mentioned.. we have to do the math in a calculator app and copy/paste the value.  This should be something really easy to do directly in the numerical field.

in the channel box you have "dash" scripting.

 

shortcut alt + RMB

 

https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/Maya/fil...

jwlove
Advocate

Ok, I wasn't sure if it was just the channel box... I think I've used it somewhere else - like in the graph editor to change the value of several keys at once (adding/subtracting a certain value across all of them).  Yes, it would be great if it could be used everywhere.

 

As far as the syntax being terrible/obscure, I don't really agree...  But that may just be due to some scripting background I have: "item += 2" is a lot better than "item = item + 2".  And I think it's pretty common shorthand in multiple scripting languages.  Granted, you probably wouldn't stumble upon it if you have little or no scripting background, but it's really not bad at all and is extremely specific in it's purpose.  I imagine they made it to only adjust the values relative to the current value with the assumption that it's what you would normally do.

 

I can't test it right now, but I think you could do something like 2 + 2 in the channel box and it would set the value to 4.  But, it would be nice to be able to divide the current value into or subtract it from another value as well - especially since the value we see in the channel box is rarely the "true" value.  Maya just rounds to a decimal place for display purposes (it may say 5.124 while the actual value is 5.xxx-xxxxxxxx) so using a calculator app to copy/paste is not exact enough... if you even need it to be.

 

Something else you could do is use a little scripting in the script editor or in the command line - it won't be as fast as just adjusting it in the channel box, but it could work as a crutch that might be better than your calculator method until something is updated in Maya.

 

for example: "1/<current value>" using a python tab in the script editor would be something like this:

import maya.cmds as mc

mc.setAttr('node.tx', 1 / mc.getAttr('node.tx'))

 

The equation you put in there will respect order of operations in case you need to make something more complicated.  If you need to do this to multiple nodes at once, there are ways to script it, but it's a little more complicated and might be worth making a python function that you can use to do it...

berjb
Contributor

@cg_oglu: thanks!  That's quite cool.  but none of the dash scripting does the sorts of things I do regularly in nuke.

 

@jwlove I definitely *understand* the syntax (I'm a software developer of 25 years).  But it's unnecessarily opaque and verbose.

 

Why type:

*= 2

 

when I can just append:

+2

 

And then I can'd do things like

 *= 1/0.45

 

I do *alot* of mel (and even some python) scripting for my work.  But there's no way I'm keen on doing:

 

import maya.cmds as mc

mc.setAttr('node.tx', 1 / mc.getAttr('node.tx'))

 

rather than just selecting the node, selecting the parameter and appending:

 

1/

 

to the beginning of the existing value.

 

The (in my opinion) completely unnecessary, confusing and sometimes dangerous visual rounding of values in channel box and attribute editor is something that should have been eliminated years ago.

 

The problem comes in this very example.

 

In the channel box type "0.00001".  The channel box will display 0.  If you do a getAttr you will see the correct value.

 

Now use the expression syntax:

 

*= 10000

 

You would expect the value to be 0.1, right?

 

It's not.  The expression evaluated to (0*10000).  And now the parameter is zero.  Very messy.

 

I just tested in maya 2018 and just typing "2 + 2" in the channel box does nothing.

 

I appreciate the thoughtful and detailed discussion.. but none of this comes even close to the very simple method that I talked about in my original post.  Something that Nuke uses to great effect.    I can appreciate that the existing syntax may make sense when you factor in that the channel box can affect multiple objects' attributes at the same time (by doubling all the tx values, for example) but there's nothing in the method I'm proposing that would preclude that functionality (something that Nuke actually doesn't support.. and should).  There's no reason maya can't interpret my appending "* 2" after the existing value to mean multiply all existing values by 2 rather than set all values to the visible value * 2. Or heck.. support both.  There's no need to remove the current functionality.

jwlove
Advocate

Sorry @berjb... based on your response, it sounds kind of like you think I was arguing against it... I'm actually not - I was just offering a work around suggestion until it gets updated in Maya (which I actually hope it does).  It wasn't the most ideal work around, but it 'works' - and typing it out every time you want to use it is a ridiculous headache, which is why I also suggested to write a function for it (you could even wrap that into a mini ui tool to make it even easier to use).  Is that ideal? No.  Would it be better to simply type in whatever math calculation into the channel box? Hands down, yes.

 

Why type "*=2" when you could just do "*2"?  My guess would be it was some super left-brained Maya programmer who added it and it was the easiest way to do it - modify the value and replace it on itself using the *= syntax.  Updating the existing ability so the channel box value is not expected to be the 'first' argument is great.  You're still a little pigeon-holed in what you could do though... for example: you could not do "1 / <current value> + 5" - you'd have to do "1/" and then "+5"  (unless I'm missing something?)

 

Also, I apologize for the 2 + 2 thing... I thought I had done it in the past but couldn't remember - it's more likely I did something along those lines in the script editor.

 

The channel box rounding issue you expanded on may be why I typically adjust values via script anyway since getAttr will return the actual true value instead of the rounded one.  I re-read my post and have no idea why it changed the decimals I put in to a string of x's... very odd... it was 5.1238.....(long string of numbers)

 

again, sorry, I probably could have been more clear on my stance for this idea 

berjb
Contributor

Oh no worries at all @jwlove I totally get where you're coming from.. I just wanted to be clear to any people from Autodesk who are reading that their current method (which, interestingly, after using Maya for 17 years I'd never heard of, haha) could be much better and much more functional.

 

For the case of modifying multiple selected values so that the typed expression would be relative to each of them individually..  you are correct that *some* sort of smarts would need to be implemented.  One method would be to just check for whichever constants of the expression match the exact value of the current visible attribute.  So if the current value is 5.256 then selecting multiple objects and typing "1/5.256 + 2*5.256" would result in "1/x + 2*x" being performed on each selected attribute.  This is a bit.. dangerous, however, since it requires some assumptions.. maybe I only wanted the first 5.256 to be substituted and the second was just coincidentally a matching value.  So something compact like typing:

 

"1/# + 2*5.256" 

 

Would produce the expected results explicitly.

 

The # could of course be replaced with any suitable placeholder that isn't a supported token in the expression grammar.

 

This would be very compact, explicit, and allow a wide range of use cases.

 

#*2 

 

would be equivalent to the current

 

*=2

 

With no extra typing.  But would allow:

 

1/(#*2)

 

As well.

 

And of course if you are selecting only one object and attribute (or want all selected attributes to get the same value) then you can ignore the # and just type the expression with only numerical constants.  No fancy syntax needed.

jwlove
Advocate

Sounds good to me - it's always good to be super clear for programmers!

 

Oh, I had a thought, and unfortunately can't test it right now, so I could be wrong.  I think if you were to highlight the actual value in the channel box and type *=2 it would take the true value whereas if you place the cursor at the end of the value and then do it the rounded number would be used...

 

maybe try that for the 0.00001 example you made?

zewt
Collaborator

> Why type:

> *= 2

> when I can just append:

> +2

 

If you mean appending it to the end of the existing string, that would only work if a single node is selected.  If you have two objects selected in different positions and you want to add 2 to both of their .tx attributes, that wouldn't work--you'd be assigning the same result to both of them.  +=2 doesn't have this problem.

 

Supporting simple expressions with a placeholder for the current value would be fine, though a variable like "n" would be better, eg. n/2, so the string is a valid Python or MEL expression, where "#/2" isn't.  Easier to type, too.  I could probably implement that in a plugin, so you could select things in the CB, then type the expression into a small docked panel (not as nice as typing directly into the CB, but functional).  Unfortunately I couldn't do that for the AE, since there's no way to select attributes in the AE.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea