Python Forum
Maya Python Noob Question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Maya Python Noob Question (/thread-10835.html)



Maya Python Noob Question - Iurii_Ledin - Jun-08-2018

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)

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)



RE: Maya Python Noob Question - Iurii_Ledin - Jun-08-2018

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.


RE: Maya Python Noob Question - Iurii_Ledin - Jun-08-2018

I just realized that i was not running the .py file correctly inside Maya.
The actual Py code is fine, i was just running each function in a separate class instance what is why it was not working correctly.