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: 

Can't set pixel aspect ratio

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
zoharl
191 Views, 2 Replies

Can't set pixel aspect ratio

Executing this, works fine:

pm.setAttr( "defaultResolution.pixelAspect", 1 )

 

When executing the following, the aspect ratio shows 1 for a fraction of a second, and then changes:

pm.setAttr( "defaultResolution.width", 100 )
pm.setAttr( "defaultResolution.height", 200 )
pm.setAttr( "defaultResolution.pixelAspect", 1 )

2 REPLIES 2
Message 2 of 3
Kahylan
in reply to: zoharl

Hi!

 

Thats because what happens with your first line is a simple display value override, not a true change in value. Once you close and reopen the rendersettings or update the rendersettings window in another way, the value returns to what is was before.

The width and height attributes trigger the rendersettings window to update as soon as Maya is idle, so thats why this is happening, the value gets changed but then the window gets updated and it gets reset.

 

This happens because the attributes deviceAspectRatio and pixelAspect are linked, and deviceAspectRatio is the attribute that actually changes the settings. If you change one of them in the render settings, Maya will calculate deviceAspectRatio from the values given and change it. This doesn't happen when you change pixelAspect via code so it gets reset according to deviceAspectRatio. You need to change deviceAspectRatio in your code to make the change permanent, this is quite simple if you know your width, height and what you want your pixelAspect to be:

 

 

import maya.cmds as mc

def setAspect(width = None, height = None, pixelAspect= None):

    mc.setAttr( "defaultResolution.width", height )
    mc.setAttr( "defaultResolution.height", width )
    
    mc.setAttr( "defaultResolution.deviceAspectRatio", (1/(width/height))*pixelAspect )
    
setAspect(width = 200, height = 100, pixelAspect= 1)

 

 

I hope it helps

 

 

Message 3 of 3
zoharl
in reply to: zoharl

I didn't understand why the pixelAspect is just for show, but your solution works. Thanks.

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

Post to forums  

Autodesk Design & Make Report