Python noob question

Python noob question

Anonymous
Not applicable
554 Views
1 Reply
Message 1 of 2

Python noob question

Anonymous
Not applicable

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)

 

 

0 Likes
555 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

It turns out... i was not loading .py file in Maya correctly. Rather dumb.
The Py part is working fine actually.

0 Likes