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 )
Solved! Go to Solution.
Solved by Kahylan. Go to Solution.
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
Can't find what you're looking for? Ask the community or share your knowledge.