Changing the level of detail of a mesh in python

Changing the level of detail of a mesh in python

Craig_Lamorte
Advocate Advocate
1,249 Views
4 Replies
Message 1 of 5

Changing the level of detail of a mesh in python

Craig_Lamorte
Advocate
Advocate

Hi,

 

I am looking for a way to edit the level of detail of a mesh, but not sure how to access that property.  In the attribute editor under Display > Drawing overrides you can find the level of detail drop down.  How would I access this option through python?  My assumption is it will be set using setAttr?

 

Capture.JPG

0 Likes
Accepted solutions (1)
1,250 Views
4 Replies
Replies (4)
Message 2 of 5

robotProdigy
Advocate
Advocate
Accepted solution

Hey Craig,

 

Yes, you assumed right. Going by what is output in the script editor when I change the level of detail of an object, I know this is a Python equivalent.

 

import maya.cmds as cm

obj_name = 'pCylinder1'

# Bounding Box
cm.setAttr(obj_name + '.overrideLevelOfDetail', 1)

# Full
cm.setAttr(obj_name + '.overrideLevelOfDetail', 0)
0 Likes
Message 3 of 5

Craig_Lamorte
Advocate
Advocate

great thanks, that is exactly what i needed! 

I also had to make sure enable override was on, took me a few guesses as to what the actual attribute was named in python 

pm.setAttr('pCube1.overrideEnabled', 1)

 

Is there documentation that shows the names of all the attributes I can tap into for objects in maya?  Its hard to guess what the correct name of that attribute is in python, even if I know where it is in the menu.

0 Likes
Message 4 of 5

robotProdigy
Advocate
Advocate

I'm pretty sure there is no documentation that shows all the attribute names of various Maya nodes (someone let me know if I'm wrong). However, if you open the script editor, and manually change object attributes in the GUI, you'll see feedback showing the attribute name (most of the time). For example, if I change the 'Enable Overrides' checkbox of an object,  this outputs in the script editor. And that's how I knew how to answer your question.

setAttr "pCylinder1.overrideEnabled" 1;

This is of course the MEL equivalent of what you eventually want in Python. But still, you can see that overrideEnabled is the attribute name. After a while, it becomes second nature to convert MEL statements to Python.

 

Another way to find hard to find attribute names is to view the node who owns the attribute you want to change in the node editor. You may need to r-click on the node and pick 'Show all attributes' to reveal ones that are hidden by default. Unfortunately, you'll see "nice" attribute names, and not the actual names you would use in code to set them. But if you connect an attribute of another node (or even from the same node) to the target attribute, again, the script editor will output the code attribute name you're looking for. It's sort of a pain, but it works.

 

0 Likes
Message 5 of 5

Craig_Lamorte
Advocate
Advocate

thanks, thats very helpful!

0 Likes