Maya ram usage and cmds.undoInfo()


#1

Hey All
First time poster.

I have an issue where im removing multiple uv sets (+500) and the Ram usage sky rockets. As a solution in the maya script editor I used cmds.undoInfo() chunk to wrap my set removal loop . but when I try to run this in an outside package it seems to eat ram like crazy . Its as if when run in the script editor it doesnt use ram … any thoughts on whats going on here . Please excuse the hacky code :slight_smile:

import maya.cmds as cmds
import psutil
import time


def create_new_uv_set(shape, uv_set_name):
"""
Create a new UV for the shape in Maya

Args:
    shape (str): the shape name
    uv_set_name (str): uv set name to create
"""
cmds.polyUVSet(shape, create=True, uvSet=uv_set_name)

def delete_uv_set(shape, uv_set_name):
"""
Delete UV for the shape in Maya and the uv set

Args:
    shape (str): the shape name
    uv_set_name (str): uv set name to create
"""
cmds.polyUVSet(shape, delete=True, uvSet=uv_set_name)
cmds.ls(selection=True)

shape = cmds.ls(selection=True)
num = 260


print "\n$$$$$$$$$$$$$ with chunk ###############"
start = time.time()
start_ram = psutil.virtual_memory()[2]

set_name = 'test'
allsets = []

cmds.undoInfo(chunkName='uv_add_chunk', openChunk=True)
for i in range(num):
uv_set_name = set_name + str(i)

# print "Creating | ", uv_set_name

allsets.append(uv_set_name)
create_new_uv_set(shape, uv_set_name)
cmds.undoInfo(chunkName='uv_add_chunk', closeChunk=True)
cmds.flushUndo()

###################################

cmds.undoInfo(chunkName='uv_remove_chunk', openChunk=True)
# print allsets
print "working",
for i, uv_set_name in enumerate(allsets):
print "-",
while psutil.virtual_memory()[2] < 80.0:
    delete_uv_set(shape, uv_set_name)
    break
print "done"
print i       
print psutil.virtual_memory()[2]

cmds.undoInfo(chunkName='uv_remove_chunk', closeChunk=True)

end = time.time()
end_ram = psutil.virtual_memory()[2]
print "time |", (end - start)
print "ram |", (end_ram - start_ram)
print "#######################################"
cmds.flushUndo()