Hi, I am trying to create an expression that use the cameras current settings. I can access most of the attributes no problem, but I cannot find a way to feed into my expression the camera's 'Angle of View' value (the Horizontal FOV). It would be great if I could just reference that float somehow.
Thanks.
Solved! Go to Solution.
Solved by trs_andre. Go to Solution.
I have managed to find this:
= `camera -q -hfv persp`
Where 'persp' is the camera name, however it wont auto-evaluate as the camera settings are changed. Evaluation is set to 'Always' in the Expression Editor.
Thanks. If I have my expression as simply:
$stereoCamFOV = `camera -q -hfv stereoCam_Shape`;
stereoCam.LensFOV = $stereoCamFOV;
The value wont auto-update as the camera settings are adjusted. I don't get any errors. If I create an unwanted extra variable from a camera shape node attribute like this:
$stereoCamFL = stereoCam_Shape.focalLength;
$stereoCamFOV = `camera -q -hfv stereoCam_Shape`;
stereoCam.LensFOV = $stereoCamFOV;
It does auto-update.
I may be going about it in a completely wrong way, but I created a new attribute on my camera node and created the the expression using the expression editor. I tried simply having: stereoCam.LensFOV = `camera -q -hfv stereoCam_Shape`
but I have had more luck storing the values in variables first.
Apologies for the late reply. Had to investigate a little further on this one.
Apparently, it has something to do with the Maya node becoming "isDirty".
Using only the line below,
persp.LensFOV = `camera -q -hfv persp`;
does make it update by clicking the edit expression button again, or simply changing your current frame, but it doesn't directly connect it to the source, so the update doesn't occur in real time.
To make it happen in real time, your approach is correct, as the following pattern is needed to make the connection successful:
$variable = existing_attribute;
$variable = command;
new_attribute = $variable;
This way, the $variable has access to both nodes and connects them.
So, you are doing the right thing!
I'm sorry for the long and complicated explanation, but I believe it is something along these lines.
Hope it served as some kind of help!
Hey, thanks very much for the detailed response. In my mind I was 'forcing' it to re-look at the attributes involved prompting the values to update. It felt like I was being a bit hacky, but it does make sense that it doesn't re-evaluate attributes it doesn't see as being involved.
I played around with forcing everything to update, but had no luck. Throwing in that unwanted variable is making it work just fine. 3DsMax had similar quirks.
Cheers again.
It's a bit too advanced for me the coding side of this.
Does any of this allow to set the FOV of current camera with a single click?
I am so tired of opening the viewport bar, selecitng cam icon and then setting up the fov in attribute editor.
My cameras in Maya constantly change FOV from whatever reason.
I wish to hard lock it or at least bring it to desirable value with a single click.
Many thanks,
DS
Well, there is no Field of View attribute on the camera object, so I'm assuming you mean Angle of View?
Angle of view is not an attribute, but an Alias that changes two different Attributes, focalLength and Filmback width/height. So to lock Angle of view you simply have to lock these attributes and nothing will happen to your FOV.
I wrote this short python script:
import maya.cmds as mc
def camLock(setAngle =True,lockAngle =True, angleValue= 60):
currentMP = mc.playblast(activeEditor =True)
currentMP = currentMP.split("|")[-1]
currentCam = mc.modelPanel(currentMP, q=True, camera=True)
currentCamShape = mc.listRelatives(s=True)
if setAngle ==True:
mc.setAttr("{}.focalLength".format(currentCam), l=False)
mc.setAttr("{}.cap".format(currentCam), l=False)
mc.camera( currentCam, e=True,hfv= angleValue)
mc.setAttr("{}.focalLength".format(currentCam), l=lockAngle)
mc.setAttr("{}.cap".format(currentCam), l=lockAngle)
camLock(setAngle =True,lockAngle =True, angleValue= 90)
just change "AngleValue" in the last line to whatever you want your angle of View to be and it will automatically change it to that value and lock the relevant attriubtes, if you run it from a shelfbutton . If you put "setAngle" to False it will just lock the attributes. if you put "lockAngle" to False it will just change the value but not lock the Attributes.
I hope it helps!
Can't find what you're looking for? Ask the community or share your knowledge.