Message 1 of 2
Python noob question
Not applicable
06-08-2018
11:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am learning Python and stuck with the task of passing the Var from one Def to another one inside a Class.
Would be very thankful for the help. Not sure what I'm doing wrong.
When executing this i get en error - # Error: ValueError: No object matches name: *_Gradient_Source #
which makes me feel that self.initial_selection was not passed from the first Def.
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)