I am learning Python and stuck with the task of passing the Var from one Def to another one inside a Class.
This is a Maya script which duplicates selected objects.
For other parts of the script i need to store both the list of initially selected objects as well as list of duplicated objects.
Would be very thankful for the help. Not sure what I’m doing wrong.
When executing this i get en error - Error: # Error: ValueError: No object matches name: *_Gradient_Source #
which makes me feel that self.initial_selection was not passed from the first Def.
(first Def seems to be running without problems)
I have also tried putting everything inside one Def and it works fine,
which again makes me feel that the problem is with passing the Variable from first Def to the Second one.
from maya import cmds
class gradient():
def __init__(self):
self.initial_selection = []
self.the_selection = []
def selection(self):
self.initial_selection = cmds.ls(selection=True)
# Check if something is selected, if not - error message
if not self.initial_selection:
nothing_selected_error_message = 'Nothing is selected. Select an object!'
raise RuntimeError(nothing_selected_error_message)
def duplication(self):
# Duplicate and rename with _Gradient_Source
for each_object in self.initial_selection:
cmds.duplicate(each_object, name='%s' % each_object + '_Gradient_Source')
# Hide original objects
cmds.select(self.initial_selection)
cmds.hide(self.initial_selection)
# Select duplicates with _Gradient_Source name
cmds.select('*_Gradient_Source')
self.the_selection = cmds.ls(selection=True)