Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How would you access a Camera's Angle of View attribute?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
moorf
2351 Views, 9 Replies

How would you access a Camera's Angle of View attribute?

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.

9 REPLIES 9
Message 2 of 10
moorf
in reply to: moorf

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.

 

 

Message 3 of 10
trs_andre
in reply to: moorf

That does seem correct, and it works on my side.

Does the Script Editor give some kind of error message?

André Moreira

Game Developer / Technical Artist

LinkedIn

Message 4 of 10
moorf
in reply to: trs_andre

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.

 

 

Message 5 of 10
trs_andre
in reply to: moorf

That's indeed strange, since the extra variable is not even being used below...

Where are you writing this expression?

(When I said it worked on my side, I was simply testing it in the script editor)

André Moreira

Game Developer / Technical Artist

LinkedIn

Message 6 of 10
moorf
in reply to: trs_andre

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.

stereoCam_FOV.png

Message 7 of 10
trs_andre
in reply to: moorf

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!

André Moreira

Game Developer / Technical Artist

LinkedIn

Message 8 of 10
moorf
in reply to: trs_andre

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.

Message 9 of 10
The-Digital-Shaman
in reply to: moorf

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

Message 10 of 10

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.

Post to forums  

Autodesk Design & Make Report