How do I set "looking through camera" on an Image Plane with Python?

Hi everyone!

I’m just starting to get my feet wet writing Python for Maya. My current project is a script to prepare layout scenes for our modelers and animators. They’ve requested that I switch the Display attribute to “looking through camera” instead of “in all views”. I can set most parameters easily enough, but that one has me stymied. When I tried to set it using the same method as everything else I’ve done, the console reported:
Error: RuntimeError: file line 1: setAttr: The attribute ‘RenderCamPlane.lookThroughCamera’ is locked or connected and cannot be modified.

So I turned on Echo All Commands and toggled it through the UI. The console gave me 93 lines of MEL, not counting comments. While I can probably go through that line by line and try to parse out what it’s doing at each step, I suspect getting some guidance would be more efficient and instructive!

For the sake of letting you know where my skills are at: I’ve been writing Lua for Blackmagic Fusion for several years, but although I’ve written a few minor scripts for PFTrack, Maya and Houdini, I’m still very much a beginner in Python.

Hi @Midgardsormr

Just a heads up. There are several flavors of Python inside Maya.
I’m using pymel below.
You can check the documentation below here.
The CMDS vanilla equivalent is here.

pm.imagePlane('plane_name', e=True, w=200, h=200, showInAllViews=True)

The key flag above is the e meaning edit. Without it, you’d be creating a new image plane rather than modifying existing one.

Also, there is a display delay. Once you execute the code, the parameters might not changed. It actually has, you just have to click away and click again your image plane.

P.S. Thanks also for your help on the BMD forums. I myself benefited from it :slight_smile:

Fantastic; thank you! Exactly what I needed.

And I’m glad to hear you’ve found my participation at BMD to be useful.