Hi!
The problem isn't really getting the information, because every object is storing it in the "displaySmoothMesh" attribute. The problem is how you store it. A very simple way to do that, is to just create a dummy node that stores the information in an attribute so the dummy node can be found later and the smoothstate restored.
Here is a python script that does this by using a script node to do so (this is a script that I just wrote to demonstrate this, so there is obviously a lot of room for improvement):
import maya.cmds as mc
import ast
def unsmoothAllObjects():
#create storing node
if mc.objExists("storeSubdiv_ScriptNode"):
storeNode = "storeSubdiv_ScriptNode"
else:
storeNode = mc.createNode("script",n = "storeSubdiv_ScriptNode" )
mc.addAttr(storeNode, ln = "subdivisionData", dt = "string")
#getting all meshes in scene
meshes = mc.ls(type = "mesh")
statesDict = {}
#storing smoothmeth preview status in dict
for m in meshes:
state = mc.getAttr('{0}.displaySmoothMesh'.format(m))
statesDict[m] = state
mc.setAttr('{0}.displaySmoothMesh'.format(m), 0)
#storing dict in attribute on storing Node
mc.setAttr('{0}.subdivisionData'.format(storeNode), statesDict, type= "string" )
def returnSmoothState():
#getting attribute from storing Node
strD = mc.getAttr("storeSubdiv_ScriptNode.subdivisionData")
#converting attribute string to dict
dict = ast.literal_eval(strD)
#restoring Smoothmesh status
for k in dict:
if mc.objExists(k):
mc.setAttr('{0}.displaySmoothMesh'.format(k), dict[k])
the fuctions for creating the Node, storing the values and unsmoothing all objects in the scene and the command for restoring the smoothstate can be triggered as follows:
unsmoothAllObjects()
returnSmoothState()
There are also other ways to permanently store variables each with their benefits/downsides. They can for example be bound to a UI, stored using option variables/global variables or exported into a separate file.
I hope it helps!