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

Maya Prefs: enable backface cull with python/mel

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
16497643852
686 Views, 7 Replies

Maya Prefs: enable backface cull with python/mel

Hello,

I have been trying to enable and disable backface cull in the maya prefs, but unfortunately it is not working for me. I am pretty sure i am missing out something really silly.

Please check the attached image

 

mel command

optionVar -list; // gives me the list of string names

optionVar -q newPolyBackFaceCull; // queried and confirmed this string is getting modified if i update manually in //prefs
optionVar -intValue newPolyBackFaceCull 1; // when i try to modify it does not work

 

any suggestions.

 

And additional query if this string is wrong, what would be the best way to find the list of strings?

 

Thank You.

7 REPLIES 7
Message 2 of 8

//Display back of faces

ToggleBackfaceGeometry;

 

//Backface Cull off

setAttr "pCubeShape5.backfaceCulling" 0;

 

//Backface Cull Full

setAttr "pCubeShape5.backfaceCulling" 3;

 

It is messed up tho, as it works only on what one manually changed in the Attribute Editor, prior to using the script.

 

I don't know how to make it apply globally or at least work on selection.

Anyone?

Message 3 of 8
brian.kramer
in reply to: 16497643852

Hi,

 

I believe you will have better success if you use the following commands to change backface culling in the Script Editor.

 

polyOptions -newPolymesh -backCulling;     // Off
polyOptions -newPolymesh -fullBack;        // On
polyOptions -newPolymesh -wireBackCulling; // Keep wire
polyOptions -newPolymesh -hardBack;        // Keep hard edges

 

These are the commands that are executed when you change the value with Preferences > Display > Polygons > Backface culling.

 

When Maya prefs are saved we sync this value up with the newPolyBackFaceCull optionVar.

 


Brian Kramer
Software Developer
Message 4 of 8

Good try Brian!

 

For me these commands work from the Display options, but not when using code directly.

There must be something more to activate them.

Message 5 of 8

After calling the various polyOptions commands create a new poly object. That new object should have the culling option you specified.

 

Try this script. It sets each culling option, creates a poly sphere, and queries the culling option.

 

file -new -force;

 

global proc printCulling()
{
    int $backCulling[] = `polyOptions -query -backCulling`;
    int $fullBack[] = `polyOptions -query -fullBack`;
    int $wireBackCulling[] = `polyOptions -query -wireBackCulling`;
    int $hardBack[] = `polyOptions -query -hardBack`;

    print("backCulling     = " + $backCulling[0] + "\n");
    print("fullBack        = " + $fullBack[0] + "\n");
    print("wireBackCulling = " + $wireBackCulling[0] + "\n");
    print("hardBack        = " + $hardBack[0] + "\n");
    print("\n");
}

 

polyOptions -newPolymesh -backCulling;
polySphere -name sphere1;
printCulling();

 

polyOptions -newPolymesh -fullBack;
polySphere -name sphere2;
printCulling();

 

polyOptions -newPolymesh -wireBackCulling;
polySphere -name sphere3;
printCulling();

 

polyOptions -newPolymesh -hardBack;
polySphere -name sphere3;
printCulling();

 


Brian Kramer
Software Developer
Message 6 of 8

Appreciate the effort. It does what you said plus erased everything from a scene.


I don't understand how does it solve anything though.

Message 7 of 8
16497643852
in reply to: 16497643852

Thank You all for the amazing replies,

 

So what i want exactly is to mention the command in `userSetup.mel`

This resolves 2 problems,

1) it will always be enabled for the whole scene and not just per object(geo)

2) even if anyone resets the prefs i'll have those settings enabled automatically once again with the help of userSetup.mel/.py

 

polyOptions work mostly with selection list(ls) as far as i know.

 

i am still trying on my end, let me know in case you guys find anything related to prefs.

 

Thanks a lot guys🙂

 

Message 8 of 8
16497643852
in reply to: 16497643852

To my surprise@brian.kramer , your option works. Thanks alot😁

 

`Prefs>display>polygons>backface culling>On`

 

%MAYA_APP_DIR%/<version>/script/userSetup.py

 

 

 

import maya.cmds as cmds
def dosomething():
    cmds.polyOptions(newPolymesh=True, fullBack=True)
    print("this is a test")
cmds.evalDeferred('dosomething()')

 

 

 

reference material

"D:\c_drive_installs\autodesk\Maya2023\scripts\startup\createPrefWndUI.mel" - the options @brian.kramer suggested, one can also refer it here

 

Unwanted stuff

I had checked polyOptions in the scene it did not work for me properly(or i did not use it properly😅), did not result me backface culling in the scene, but while going through all the options once again i noticed the option in `Prefs do update`

 

I was too adamant to solve it in this manner - because the docs say so

optionVar - This command allows you to set and query variables which are persistent between different invocations of Maya. These variables are stored as part of the preferences.

optionVar -list; // gives me the list of string names

optionVar -q newPolyBackFaceCull; // queried and confirmed this string is getting modified if i update manually in //prefs
optionVar -intValue newPolyBackFaceCull 1; // when i try to modify it does not work

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

Post to forums